Keras-NASNet
Keras-NASNet copied to clipboard
how to load pretrain model?
hello @titu1994 , I am using your code to train my dataset, and i want to train it with a pretrain model that you provide in nasnet.py. But the problem is that my category is 361, and the pre-trained model is 1000, how do I modify it? Looking forward for your reply! : )
I build a model to load the pretrain model's weight as this: model = NASNetLarge((img_rows, img_cols, img_channels), use_auxiliary_branch=True, include_top=True)
but i get this error:
Traceback (most recent call last): File "/root/anaconda3/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1567, in _create_c_op c_op = c_api.TF_FinishOperation(op_desc) tensorflow.python.framework.errors_impl.InvalidArgumentError: Dimension 0 in both shapes must be equal, but are 1 and 128. Shapes are [1,1,2688,128] and [128,2016,1,1]. for 'Assign_1524' (op: 'Assign') with input shapes: [1,1,2688,128], [128,2016,1,1].
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "train.py", line 70, in
Do you know what's wrong? Thank you very much!
You must have used an odd input shape here. Can you provide the full script with all variables ?
here is my all variables:
lr_reducer = ReduceLROnPlateau(factor=np.sqrt(0.5), cooldown=0, patience=5, min_lr=0.5e-5)
csv_logger = CSVLogger('NASNet-objction-classfication.csv')
model_checkpoint = ModelCheckpoint(weights_file, monitor='val_predictions_acc', save_best_only=True, save_weights_only=True, mode='max')
batch_size = 128
nb_classes = 361
nb_epoch = 200 # should be 600
data_augmentation = True
# input image dimensions
img_rows, img_cols = 331, 331
img_channels = 3
when i set
use_auxiliary_branch=False, include_top=False
and add code in my script. The model can be trained successfully. But another problem is when i can only set batch size to 16,otherwise it will OOM. My machine is P40.
base_model = NASNetLarge((img_rows, img_cols, img_channels), use_auxiliary_branch=False, include_top=False)
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dropout(dropout)(x)
predictions = Dense(nb_classes, activation='softmax', kernel_regularizer=l2(weight_decay), name='predictions')(x)
model = Model(inputs=base_model.input, outputs=predictions)
model.summary()
Weird. I don't get this error. I an using TF with Channs last data format. I'm guessing you are having the same, so I don't understand the cause.
Yes, I am using the generator function in imagenet_validation.py.
hello @titu1994 , How big is your model's batch size when you trained large nasnet?
@titu1994 Same Issue Here, I think there is a problem while loading auxiliary_brach weights..