My lab ID is ilkmrowr.
After successfully completing the assignment, I tried the last cell, which trains the VGG architecture to see how well it works. Although I did not encounter timeout errors, the net did not learn the dataset - its accuracy was ~ 50%.
So, I created another notebook (C1W4_Testing), where I experimented and found smaller networks performed much better. I suspect the issue was one of overtraining, but don’t know how to verify that - i.e. how can I get metrics to output training as well as validation set accuracy? I can’t find that in the docs.
I also experimented with a sequential architecture, which I thought was equivalent to my final functional style architecture. Oddly, the sequential architecture performed much better than the functional style architecture, though drastically more slowly. Does this make sense?
If I want to post some of my code and questions to StackOverflow, would that violate any of Coursera’s terms – as long as I don’t explicitly identify the code as Coursera related?
i.e.
# For reference only. Please do not uncomment in Coursera Labs because it might cause the grader to time out.
# You can upload your notebook to Colab instead if you want to try the code below.
# Download the dataset
dataset = tfds.load('cats_vs_dogs', split=tfds.Split.TRAIN, data_dir='data/')
# Initialize VGG with the number of classes
vgg = MyVGG(num_classes=2)
# Compile with losses and metrics
vgg.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
# Define preprocessing function
def preprocess(features):
# Resize and normalize
image = tf.image.resize(features['image'], (224, 224))
return tf.cast(image, tf.float32) / 255., features['label']
# Apply transformations to dataset
dataset = dataset.map(preprocess).batch(32)
# Train the custom VGG model
vgg.fit(dataset, epochs=10)
Epoch 1/10
727/727 [==============================] - 446s 614ms/step - loss: 0.6932 - accuracy: 0.4975
Epoch 2/10
727/727 [==============================] - 445s 612ms/step - loss: 0.6932 - accuracy: 0.4996
Epoch 3/10
727/727 [==============================] - 444s 611ms/step - loss: 0.6932 - accuracy: 0.4994
Epoch 4/10
727/727 [==============================] - 442s 607ms/step - loss: 0.6932 - accuracy: 0.5003
Epoch 5/10
727/727 [==============================] - 442s 608ms/step - loss: 0.6932 - accuracy: 0.4999
Epoch 6/10
727/727 [==============================] - 441s 607ms/step - loss: 0.6932 - accuracy: 0.4998
Epoch 7/10
727/727 [==============================] - 442s 608ms/step - loss: 0.6932 - accuracy: 0.5000
Epoch 8/10
727/727 [==============================] - 443s 609ms/step - loss: 0.6932 - accuracy: 0.5000
Epoch 9/10
727/727 [==============================] - 443s 609ms/step - loss: 0.6932 - accuracy: 0.5000
Epoch 10/10
727/727 [==============================] - 443s 610ms/step - loss: 0.6932 - accuracy: 0.5000
<tensorflow.python.keras.callbacks.History at 0x7f50023f9490>