Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finetune the model you provided error #347

Open
shihanyu opened this issue Feb 22, 2023 · 3 comments
Open

finetune the model you provided error #347

shihanyu opened this issue Feb 22, 2023 · 3 comments

Comments

@shihanyu
Copy link

I wanted to finetune the model "Cell_Painting_CNN_v1.hdf5", but error accured. says(1280,490) and (1280,327) does not match.

and I compared "Cell_Painting_CNN_v1.hdf5" and a model I trained from pretrained model in imagenet,their sizes are different.

so is there any way to let me finetune the model based on "Cell_Painting_CNN_v1.hdf5"?

@jccaicedo
Copy link
Member

It should be possible to fine-tune it. Are you trying to finetune on a set of Cell Painting images? What is the size of your input images, including height, width and channels?

@jccaicedo
Copy link
Member

@Arkkienkeli do you have any suggestion?

@Arkkienkeli
Copy link
Member

Hi @shihanyu, it looks like that you load classification head, while in finetuning you need to you use your own classification head (490 is the number of classes we used to train the model, 327 is apparently the number of classes in your dataset).

Here is the short example how you could use the model outside DeepProfiler:

#Input shape
image_shape = (128,128,5)
input_image = tf.compat.v1.keras.layers.Input(image_shape)

# Initilize model object, without weights for now. 
model_conv_cnn = efn.EfficientNetB0(input_tensor=input_image, include_top = False, weights = None)

features = tf.compat.v1.keras.layers.GlobalAveragePooling2D(name="pool5")(model_conv_cnn.layers[-1].output)

# Number of classes from your dataset. 490 - number of classes in Cell Painting dataset. Make an output layer. You can change the number of classes as you wish. 
number_of_classes = 490
class_outputs = []
y = tf.compat.v1.keras.layers.Dense(number_of_classes, activation="softmax", name="ClassProb")(features)
class_outputs.append(y)

# Join new input and output layers with the model and load weights. 
model_conv_cnn = tf.compat.v1.keras.models.Model(inputs=model_conv_cnn.input, outputs=class_outputs)
model_conv_cnn.load_weights('Cell_Painting_CNN_v1.hdf5')

# Compile a model. 
optimizer = tf.compat.v1.keras.optimizers.SGD()
loss = tf.compat.v1.keras.losses.CategoricalCrossentropy()

model_conv_cnn.compile(optimizer, loss)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants