Train resnet50 from scratch and finetune the pretrained resnet50 to do prediction

how to train resnet50 from scratch and how to finetune it?
Can anybody give me an example?
Would be thankful

The PyTorch ImageNet example might be a good starter for training the model from scratch (alternatively, check e.g. FastAI to use the latest training tips). Once this is done, you could use the finetuning tutorial to finetune your model.

Thank you so much. It is helpful. I have a question in the training loss. I found that the training loss converge slowly. Could you please tell me how to imporve this?

The convergence depends on e.g. the used optimizer, its hyperparameters etc.
You could either run experiments using different training setups (based e.g. on the latest research) or check what training scripts in other repositories are using. As already mentioned before, FastAI has always stressed out to use the latest training techniques for a fast default convergence.

Thanks for your suggestion. I did not initialize the parameters. It is said that in pytorch the __init__function has been designed to initialize model parameters automatically. Is that right?

You could usually initialize all nn.Paremeters, buffers, and other submodules in the nn.Module.__init__ method. Afterwards you could use these objects in the foward.
Each pre-defined module would then initialize its parameters via the reset_parameters() method as seen e.g. here for nn.Linear.