PracticalDL/Practical-Deep-Learning-Book

Chapter 4: Fine tuned feature embeddings -> calculate from output or intermediate layer?

Closed this issue · 4 comments

Congratulations on an amazing book. Excellent so far!

I noticed in the image search project in Chapter 4 that the feature embeddings for the out of the box ResNet50 model are calculated from an intermediate layer (GlobalMaxPooling2D) (None, 2048).

But after fine tuning based on our own dataset the features are calculated based on the final output layer and hence the feature dimensions become more like (1, 10) based on the number of classes in our dataset.

I'm not sure is this an error/oversight or if both methodologies are correct?
Would love to get your opinion on this. And if a fix is needed I can offer to help also.
Thanks again for the great book.
Niall

Can you please point out the exact code you are referring to. I think you are talking about the PCA section, but confirmation (like page number/line number) would be helpful.

model_finetuned = model_maker()
model_finetuned.compile(loss='categorical_crossentropy',
optimizer=tensorflow.keras.optimizers.Adam(0.001),
metrics=['acc'])
model_finetuned.fit_generator(
train_generator,
steps_per_epoch=math.ceil(float(TRAIN_SAMPLES) / batch_size),
epochs=10)

and i received this error

InvalidArgumentError: logits and labels must be broadcastable: logits_size=[64,101] labels_size=[64,102]
[[node loss/dense_3_loss/softmax_cross_entropy_with_logits (defined at :8) ]] [Op:__inference_distributed_function_509756]

Function call stack:
distributed_function

Did you follow the instruction near the top of the notebook that said the following?

Note that there is a 102nd category called ‘BACKGROUND_Google’ consisting of random images not contained in the first 101 categories, which needs to be deleted before we start experimenting.
$ rm -rf datasets/caltech101/BACKGROUND_Google

background_GOOGLE

I'm closing this issue now, since there has been no activity in the past 2 weeks.