I'm using Roboflow to create a tfrecord file and I don't know how to use that in Keras

Question:

I’ve tried many tutorials online, but they don’t work at all.
The mnist dataset can just use tf.keras.datasets.mnist.load_data

(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data(datapath)
model = keras.models.Sequential([
    layers.Conv2D(filters=16, kernel_size=(5,5), padding='same',
                 input_shape=(28,28,1),  activation='relu'),
    layers.MaxPooling2D(pool_size=(2, 2)),
    layers.Conv2D(filters=36, kernel_size=(5,5), padding='same',
                 activation='relu'),
    layers.MaxPooling2D(pool_size=(2, 2)),
    layers.Dropout(0.25),
    layers.Flatten(),
    layers.Dense(128, activation='relu'),
    layers.Dropout(0.5),
    layers.Dense(10,activation='softmax')
])
model.fit(x=x_train, y=y_train, validation_split=0.2, 
                        epochs=30, batch_size=128, verbose=1)  

But how can I get these :(x_train, y_train), (x_test, y_test) from the tfrecord file?

I’m a new learner to this, hope you can help me out.

Asked By: leo

||

Answers:

A TFRecord file is a binary format kind of like a zip file. It can contain many things in many layouts so they’re not interchangeable. Your TFRecord needs to be formatted in the way your model expects.

The TFRecord Roboflow exports is in a specific layout meant to be used with Tensorflow Object Detection like in this blog post*. It probably won’t work for MNIST (which is classification).

* Note: this framework is pretty outdated and not very popular these days. I wouldn’t recommend using it if you’re starting from scratch.

Answered By: Brad Dwyer
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.