Open karllandheer opened 1 year ago
You must first create the model after load weights:
from classification_models_3D.tfkeras import Classifiers
modelPoint, preprocess_input = Classifiers.get('mobilenetv2')
model = modelPoint(input_shape=(128, 128, 128, 3), include_top=False, weights=None)
model.load_weights('MobileNetModel.h5')
You can try like this, but I see it doens't work for me:
from classification_models_3D.models._DepthwiseConv3D import DepthwiseConv3D
model = tensorflow.keras.models.load_model(
'MobileNetModel.h5',
custom_objects={'DepthwiseConv3D': DepthwiseConv3D}
)
Hello, thank you for your prompt response. If I try your code (modified to my shape):
from classification_models_3D.tfkeras import Classifiers modelPoint, preprocess_input = Classifiers.get('mobilenetv2') model = modelPoint(input_shape=(32, 128, 128, 1), weights=None, encoder_weights=None) model.load_weights('MobileNetModel.h5')
I get this error:
You are trying to load a weight file containing 125 layers into a model with 105 layers.
My model has been instantiated with this code:
model = sm.Unet('mobilenetv2',weights=None,input_shape=input_model_shape,encoder_weights=None)
Could I just use the above line, and do model.load_weights('MobileNetModel.h5')? I ask because when I tried this my model spits out all 0s, even though the training IOU is ~0.7. Wondering if perhaps this method of loading weights isn't quite right?
You didn't say in first message which model you used.
Try this:
model = sm.Unet('mobilenetv2',weights=None,input_shape=input_model_shape,encoder_weights=None)
model.load_weights('MobileNetModel.h5')
Check if during training and inference you have the same preprocessing of volumes.
Hello, I have identical preprocessing of volumes. For example if I run this:
But when I run model.evaluate I get this (this agrees with what I get when I use model.predict):
Not sure if this is related to segmentation_models_3D or keras more broadly
Unfortunately I don't know why result is like this... (
Interesting, thank you for your response. Have you trained models with mobilenetv2? Perhaps it's an inherent bug related to this model. This seems to be exactly the issue I am getting:
No I never tried mobilenetv2 model for 3D tasks. I propose you to try resnet18_3D first. It also not so large and may be you avoid this problem.
OK, I will try that and get back to you. I tried resnet18 first but it was training slow so I swapped, but maybe this is an inherent issue to mobilenet
Hello, when I try to load a model which used a mobilenetv2 backbone:
model = tensorflow.keras.models.load_model(MobileNetModel.h5',compile=False)
I get this issue:
ValueError: Unknown layer: DepthwiseConv3D. Please ensure this object is passed to the
custom_objects
argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.Any ideas on how to fix this?