[Slim] Scripts for Training ResNet From Scratch
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 14.04
- TensorFlow installed from (source or binary): Source
- TensorFlow version (use command below): 1.0.0
- CUDA/cuDNN version: 8.0
- GPU model and memory: 6xK80
- Exact command to reproduce: See below
Describe the problem
Although it is stated in the slim model that train_image_classifier.py can be used to train models from scratch, I found it really hard in practice without any working example. In my case, I am trying to train ResNet from scratch on a local machine with 6xK80s. After spending much time figuring out the difference between replica and clone arguments and how effective batch size is computed, I came up with this script:
DATASET_DIR=/nv/hmart1/ashaban6/scratch/data/imagenet_RF_record
TRAIN_DIR=/nv/hmart1/ashaban6/scratch/train_dir
DEPTH=50
NUM_CLONES=8
CUDA_VISIBLE_DEVICES="0,1,2,3,4,5,6,7,8" python train_image_classifier.py --train_dir=${TRAIN_DIR} --dataset_name=imagenet --model_name=resnet_v1_${DEPTH} --max_number_of_steps=100000000 --batch_size=32 --learning_rate=0.1 --learning_rate_decay_type=exponential --dataset_split_name=train --dataset_dir=${DATASET_DIR} --optimizer=momentum --momentum=0.9 --learning_rate_decay_factor=0.1 --num_epochs_per_decay=30 --weight_decay=0.0001 --num_readers=12 --num_clones=$NUM_CLONES
I followed the same settings as is suggested in the paper. I am using 8 GPUs on a local machine with batch_size 32 so the effective batch size is 32x8=256. Learning rate is initially set to 0.1 and will be decayed by 10 every 30 epochs. After 70K steps (70000x256/1.2e6 ~ 15 epochs), the top-1 performance on the validation set is as low as ~14% while it should be around 50% after that many iterations. I used this command to get the top-1 performance:
DATASET_DIR=/nv/hmart1/ashaban6/scratch/data/imagenet_RF_record
CHECKPOINT_FILE=/nv/hmart1/ashaban6/scratch/train_dir/
DEPTH=50
CUDA_VISIBLE_DEVICES="10" python eval_image_classifier.py --alsologtostderr --checkpoint_path=${CHECKPOINT_FILE} --dataset_dir=${DATASET_DIR} --dataset_name=imagenet --dataset_split_name=validation --model_name=resnet_v1_${DEPTH}
With the lack of working examples it is hard to say if there is a bug in the slim training code or a problem in my script. Providing a working script would be really helpful.
@nathansilberman @sguada can you comment?
Could you copy the loss and global_steps/sec plots from TensorBoard, to make sure the loss is going down as expected?
Thanks for your response @sguada. I've attached the plots that you asked for. The accuracy after 100k steps is 22%. I can tell from the plots and the validation accuracy that it is converging but really slow. The slow convergence might imply that the optimization is done for only one clone with batch_size 32 but I can tell from the graph that there are 8 clones in total, one on each GPU. The learning rate was fixed to 0.1 during the training (there is no LR decay before 100k), momentum 0.9 and I am using momentum optimizer.

I realized that you have not trained resent_v1 with this code. I also tried resnet_v2 and got a very similar plots. That would be great if you could share a working script for training resnet_v2 that I can use and see if I can reproduce your results.
@sguada Anything you could say from the plots?
What data are you training with this? Are you trying to train image-net data itself on your resnet model?
Yes, I am.
Is there any progress ? I suffer from the same issue. Even though the RMSProp or Adam optimizer is applied , it still seems to be hard to converge.
Nope, I still don't know what is the problem...
Same issue for me here, I cant get accuracy above 70% as claimed in the paper for mobilenet and resnet50. top1 accuracy stays around 60%. this is training strategy issue?
I'm really struggling with training a Resnet-50 from scratch (for classification) also. Is there something wrong with the implementation?
@sguada, do you have any input on this? Is there any Slim Imagenet model that was tested to correctly train from scratch, or are they all mere ports of models train in Caffe? We can't depend on these ancient weight sets forever..
same problem, my training of Resnet-18 reported a 58% top1 accuracy, and would not decrease anymore. Data augment and different optimizer ware tried. @kakpple Do you get any better result?
Hi There, We are checking to see if you still need help on this, as this seems to be considerably old issue. Please update this issue with the latest information, code snippet to reproduce your issue and error you are seeing. If we don't hear from you in the next 7 days, this issue will be closed automatically. If you don't need help on this issue any more, please consider closing this.