Supervision Type for Weights of ResNet50 Pre-Trained on ImageNet

29 views
Skip to first unread message

Louis Kwak

unread,
Nov 29, 2023, 1:05:48 PM11/29/23
to Keras-users
Hello,

A newcomer both to this group and to neural nets in general...:)
I am trying to create a image classification network with code that looks like as follows:

==============code starts==============
from keras.applications.resnet50 import ResNet50
from keras.layers import GlobalMaxPooling2D, GlobalAveragePooling2D, Dense, BatchNormalization, Lambda, Dropout
from keras import Sequential
from keras.optimizers import RMSprop
import numpy as np

#(...)

a,b = map(int,input("Please enter the category type interval a, b to be run:").split(','))

base = ResNet50(weights='imagenet', include_top=False)
for layer in base.layers:
    layer.trainable = False

model = Sequential()
model.add(base)
model.add(GlobalAveragePooling2D())
model.add(BatchNormalization())
model.add(Dense(256, activation='relu', trainable = True))
model.add(BatchNormalization())
model.add(Dense(b-a+1, activation='softmax', trainable = True))
model.compile(loss='categorical_crossentropy', optimizer=RMSprop(lr=2e-5), metrics=['accuracy'])
==============code ends==============

Here, I load Keras's ResNet50 with weights pre-trained on ImageNet with the parameter weights set as 'imagenet'. In this case, must this pre-training have been unsupervised--i.e. irrespective of the WordNet hierarchy that ImageNet follows?

This matters to me because I am trying to create a network that can be 'bilingually trained'; I would absolutely prefer the ResNet50 to have gone through unsupervised training, so that the network classifies images purely according to the images and not to the (English-specific) labels too.

Lance Norskog

unread,
Dec 1, 2023, 5:50:46 AM12/1/23
to Louis Kwak, Keras-users
It is possible that the latent space created by Resnet is not a pure mapping of images to unique labels; there might be some pollution of English language structure in the latent positions created for images. But it seems like it should be very minor?

Good luck,

Lance Norskog

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keras-users/48bd1399-dfe8-4468-83d2-ef460836fcabn%40googlegroups.com.


--
Lance Norskog
lance....@gmail.com
Redwood City, CA

Matias Valdenegro

unread,
Dec 1, 2023, 6:05:20 PM12/1/23
to keras...@googlegroups.com

No, the pre-trained weights for ImageNet were obtained via supervised learning using class labels (not the whole wordnet hierarchy).

Reply all
Reply to author
Forward
0 new messages