automl icon indicating copy to clipboard operation
automl copied to clipboard

best practice for setting new num_classes on custom dataset?

Open lessw2020 opened this issue 6 years ago • 3 comments

Hi - is there any documentation or tips on adjusting efficientdet for custom datasets in terms of resetting for new num_classes? I see I can adjust the hparams directly ala: `config = hparams_config.get_detection_config(model_name) ... config.num_classes=6'

and obviously my train/validate json is setup for the six classes, but is that sufficient to begin fine tuning or do we need to clear/reset anything else in the code or at model instantatiation? I'm still setting up the custom training loop by updating main.py but appreciate any tips to speed things up for custom implementations. Thanks very much!

lessw2020 avatar Apr 08 '20 01:04 lessw2020

You can add num_classes=6 to --hparams

!python main.py --mode=train_and_eval \
    --training_file_pattern=tfrecord/pascal*.tfrecord \
    --validation_file_pattern=tfrecord/pascal*.tfrecord \
    --val_json_file=tfrecord/json_pascal.json \
    --model_name=efficientdet-d0 \
    --model_dir=/tmp/efficientdet-d0-scratch  \
    --backbone_ckpt=efficientnet-b0  \
    --train_batch_size=8 \
    --eval_batch_size=8 --eval_samples=512 \
    --num_examples_per_epoch=5717 --num_epochs=1  \
    --hparams="use_bfloat16=false,num_classes=6,moving_average_decay=0" \
    --use_tpu=False

vincent7293 avatar Apr 08 '20 02:04 vincent7293

Restoring parameters from /tmp/model_dir/efficientdet-d0-scratch/model.ckpt-0
ERROR:tensorflow:Error recorded from training_loop: Restoring from checkpoint failed. This is most likely due to a mismatch between the current graph and the graph from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:

Assign requires shapes of both tensors to match. lhs shape= [54] rhs shape= [180]
	 [[node save/Assign_223 (defined at main.py:358) ]]

Errors may have originated from an input operation.
Input Source operations connected to node save/Assign_223:
 class_net/class-predict/bias/Momentum (defined at /home/oriuser/mounted/efficientdet/det_model_fn.py:474)

Wow, i add num_classes=6 and have a problem with shapes of layers. It's happens because using checkpoint with 20 classes classifier.

UPD: Omg, i'm stupid, i'm running with non-empty model_dir, and checkpoint loaded with another shape!=)

Thank you for your realization!

takentui avatar Apr 08 '20 11:04 takentui

Ok passing in the desired num classes into main.py is doing the trick: ala !python main.py --mode=train_and_eval \ --num_classes=6 \

so seems it's as simple as that for now. thus closing this issue :)

lessw2020 avatar Apr 09 '20 05:04 lessw2020