我正在尝试解析我的 tfrecord 数据集以将其用于对象检测。当我试图将我的稀疏张量更改为密集张量时,出现以下我无法理解的错误:
ValueError: Shapes must be equal rank, but are 1 and 0
From merging shape 3 with other shapes. for '{{node stack}} = Pack[N=5, T=DT_FLOAT, axis=1](SparseToDense, SparseToDense_1, SparseToDense_2, SparseToDense_3, Cast)' with input shapes: [?], [?], [?], [?], [].
我的 feature_description 是:
feature_description = {
'image/filename': tf.io.FixedLenFeature([], tf.string),
'image/encoded': tf.io.FixedLenFeature([], tf.string),
'image/object/bbox/xmin': tf.io.VarLenFeature(tf.float32),
'image/object/bbox/ymin': tf.io.VarLenFeature(tf.float32),
'image/object/bbox/xmax': tf.io.VarLenFeature(tf.float32),
'image/object/bbox/ymax': tf.io.VarLenFeature(tf.float32),
'image/object/class/label': tf.io.VarLenFeature(tf.int64),
}
我的解析代码:
def _parse_image_function(example_proto):
# Parse the input tf.Example proto using the dictionary above.
return tf.io.parse_single_example(example_proto, feature_description)
def _parse_tfrecord(x):
x_train = tf.image.decode_jpeg(x['image/encoded'], channels=3)
x_train = tf.image.resize(x_train, (416, 416))
labels = tf.cast(1, tf.float32)
# print(type(x['image/object/bbox/xmin']))
tf.print(x['image/object/bbox/xmin'])
y_train = tf.stack([tf.sparse.to_dense(x['image/object/bbox/xmin']),
tf.sparse.to_dense(x['image/object/bbox/ymin']),
tf.sparse.to_dense(x['image/object/bbox/xmax']),
tf.sparse.to_dense(x['image/object/bbox/ymax']),
labels], axis=1)
paddings = [[0, 100 - tf.shape(y_train)[0]], [0, 0]]
y_train = tf.pad(y_train, paddings)
return x_train, y_train
def load_tfrecord_dataset(train_record_file, size=416):
dataset=tf.data.TFRecordDataset(train_record_file)
parsed_dataset = dataset.map(_parse_image_function)
final = parsed_dataset.map(_parse_tfrecord)
return final
我的错误是什么?
繁华开满天机
相关分类