I’m downloading a TFRecord data set from Roboflow, and parsing it to be used by tf.keras.applications.mobilenet.MobileNet.
I run the data set through this function:
def parse_tfrecord_fn(example):
feature_description = {
'image/object/bbox/ymax': tf.io.FixedLenFeature([1], tf.float32),
'image/encoded': tf.io.FixedLenFeature([], tf.string),
'image/height': tf.io.FixedLenFeature([1], tf.int64),
'image/object/bbox/ymin': tf.io.FixedLenFeature([1], tf.float32),
'image/filename': tf.io.FixedLenFeature([1], tf.string),
'image/format': tf.io.FixedLenFeature([1], tf.string),
'image/width': tf.io.FixedLenFeature([1], tf.int64),
'image/object/bbox/xmin': tf.io.FixedLenFeature([1], tf.float32),
'image/object/bbox/xmax': tf.io.FixedLenFeature([1], tf.float32),
'image/object/class/text': tf.io.FixedLenFeature([3], tf.string),
'image/object/class/label': tf.io.FixedLenFeature([1], tf.int64),
}
example = tf.io.parse_single_example(example, feature_description)
image = tf.image.decode_jpeg(example['image/encoded'], channels=3)
label = example['image/object/class/label']
image = tf.image.resize(image, (224, 224))
image = tf.keras.applications.mobilenet.preprocess_input(image)
return image, label
After processing my data set on it, parsed_dataset = dataset.map(parse_tfrecord_fn)
, I do the following:
base_model = MobileNet(weights = 'imagenet', include_top=False)
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(128, activation='relu')(x)
output = Dense(num_features, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=output)
I then compile and fit the model
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
batch_size=30
num_epochs = 1000
model.fit(parsed_dataset.batch(batch_size), epochs=num_epochs, verbose=1)
However, due to model.fit(parsed_dataset.batch(batch_size), epochs=num_epochs, verbose=1)
, I get the error:
InvalidArgumentError: Graph execution error:
Key: image/object/class/text. Can’t parse serialized Example.
[[{{node ParseSingleExample/ParseExample/ParseExampleV2}}]]
[[IteratorGetNext]] [Op:__inference_train_function_112072]
I’ve tried going through the Stack Overflow posts discussing this problem: python - Tensorflow TFRecord: Can't parse serialized example - Stack Overflow.
Could you please let me know how to approach this problem?
Project Type: Object Detection
OS: MacOS
Project Universe Link or Workspace/Project ID: Accessible Train Station