EfficientNet-PyTorch icon indicating copy to clipboard operation
EfficientNet-PyTorch copied to clipboard

[Feature request] Add the Noisy Students pretrained weights

Open Cyril9227 opened this issue 5 years ago • 17 comments

Hello @lukemelas ,

Thank's for your amazing work. Do you have any plans to incorporate the pretrained weights using noisy students scheme? Weights are available for the TPU / Tensorflow version, not really sure how to port these into Pytorch tho.

Thank's !

Cyril9227 avatar Feb 12 '20 03:02 Cyril9227

You can try the conversion script in the tf_to_pytorch directory.

chenshen03 avatar Feb 12 '20 07:02 chenshen03

Yes, I'll add the noisy students version soon. I'm a bit swamped with work at the moment, but I'll convert the weights, run the tests, and make them available as soon as I get a chance.

lukemelas avatar Feb 12 '20 16:02 lukemelas

Yes, I'll add the noisy students version soon. I'm a bit swamped with work at the moment, but I'll convert the weights, run the tests, and make them available as soon as I get a chance.

Nice ! Looking forward to it, thanks

Cyril9227 avatar Feb 13 '20 03:02 Cyril9227

Yes, I'll add the noisy students version soon. I'm a bit swamped with work at the moment, but I'll convert the weights, run the tests, and make them available as soon as I get a chance.

+1 looking forward. Thanks!

Selimonder avatar Feb 20 '20 16:02 Selimonder

You can try the conversion script in the tf_to_pytorch directory.

It seems that leads to error that it can't find the missing keys

Soonhwan-Kwon avatar Feb 29 '20 17:02 Soonhwan-Kwon

I tried porting it too. Most of the errors I got were patched using tf.compat.v1 wherever it complained—except tf.train.Saver(), which apparently doesn't exist.

EDIT: was able to get around that too with:

import tensorflow.compat.v1 as tf1
tf1.disable_v2_behavior()

And then using tf1 for the .Saver methods, and using regular tf (2) for all other calls. For reference, here is the noisy student b3 pytorch model. Hasn't been tested but this is what was spit out of the conversion script w/o error: https://drive.google.com/file/d/1bOYh7KkhQfW1HQwzSzyqOuxdITaRpCzq/view?usp=sharing

authman avatar Mar 01 '20 04:03 authman

You can try the conversion script in the tf_to_pytorch directory.

It seems that leads to error that it can't find the missing keys

The network structure of NoisyStudent and EfficientNet is the same, so you can add key fields similar to EfficientNet and other conditional judgments to the conversion codes.

chenshen03 avatar Mar 01 '20 05:03 chenshen03

@authman @chenshen03 I finally make it work with tensorflow==1.14.0, and it works perfectly Thank you

Soonhwan-Kwon avatar Mar 01 '20 07:03 Soonhwan-Kwon

I tried porting it too. Most of the errors I got were patched using tf.compat.v1 wherever it complained—except tf.train.Saver(), which apparently doesn't exist.

EDIT: was able to get around that too with:

import tensorflow.compat.v1 as tf1
tf1.disable_v2_behavior()

And then using tf1 for the .Saver methods, and using regular tf (2) for all other calls. For reference, here is the noisy student b3 pytorch model. Hasn't been tested but this is what was spit out of the conversion script w/o error: https://drive.google.com/file/d/1bOYh7KkhQfW1HQwzSzyqOuxdITaRpCzq/view?usp=sharing

Has someone tested it already ?

Thank's tho !

Cyril9227 avatar Mar 02 '20 07:03 Cyril9227

I've tested it and it works great. I've also converted b4 if anyone is interested.

authman avatar Mar 02 '20 19:03 authman

I've tested it and it works great. I've also converted b4 if anyone is interested.

Cool, thank's for the feedback, will give it a try unless @lukemelas releases an official version for them

Cyril9227 avatar Mar 03 '20 07:03 Cyril9227

I've tested it and it works great. I've also converted b4 if anyone is interested.

Cool! Could you share your weight file?

seefun avatar Mar 10 '20 04:03 seefun

I've tested it and it works great. I've also converted b4 if anyone is interested.

Is it possible to get the converted weights for b4?

laurentdillard avatar Mar 27 '20 17:03 laurentdillard

https://drive.google.com/file/d/1hORyc4b8_QPs1O67br5T_a9XeB92ICkF/view?usp=sharing B4 noisy student pth.

authman avatar Mar 27 '20 21:03 authman

Any updates on this? Did anyone convert b5 and the larger ones already?

ngessert avatar Jun 12 '20 23:06 ngessert

You guys can easily convert the files yourselves. There is a script in this very repo:

https://github.com/lukemelas/EfficientNet-PyTorch/tree/master/tf_to_pytorch

Use it to download tf weights and convert to .pth. For example, I navigated to https://github.com/tensorflow/tpu/tree/master/models/official/efficientnet, and downloaded NoisyStudent + RA EfficientNet's B2 tensorflow .ckpt. Untar'd the file into the pretrained_tensorflow directory.

Then ran this:

python load_tf_weights.py --model_name efficientnet-b2 --tf_checkpoint ../pretrained_tensorflow/noisy-student-efficientnet-b2/ --output_file ../pretrained_pytorch/noisy-student-efficientnet-b2.pth which resulted in a .pth file ready to rock and roll.

If you have errors with load_tf_weights.py due to it or .any of the other scripts complaining about being written in tf1.x, here's a copy of the code I've altered such that it runs just fine with tensorflow-2.2.0: https://drive.google.com/file/d/11jDyfRKoIhVpuNsFSeR_SAFe0e0R0fA1/view?usp=sharing

Maybe some less lazy than I can take the code and turn it into a PR?

authman avatar Jul 02 '20 18:07 authman

Hello @authman , Thanks for sharing your script for TF-2.2.0. When I try the same procedure you mentioned above, I get an error reading the checkpoint. I get the same error with the original script and TF-1.15.0 as well. I have verified that directories and extracted checkpoints do exist at the mentioned paths. The function tf.train.latest_checkpoint(checkpoint_dir) is returning None for some reason. Any suggestions?

Script that I run:

python3 load_tf_weights.py \
--model_name efficientnet-b4 \
--tf_checkpoint ../pretrained_tensorflow/noisy-student-efficientnet-b4/ \
--output_file ../pretrained_pytorch/noisy-student-efficientnet-b4.pth
Traceback (most recent call last):
  File "load_tf_weights_tf2.py", line 167, in <module>
    load_and_save_temporary_tensorflow_model(args.model_name, args.tf_checkpoint)
  File "load_tf_weights_tf2.py", line 138, in load_and_save_temporary_tensorflow_model
    eval_ckpt_driver.restore_model(sess, model_ckpt)
  File "original_tf/eval_ckpt_main.py", line 92, in restore_model
    saver.restore(sess, checkpoint)
  File "/home/jvm6526/.local/lib/python3.6/site-packages/tensorflow/python/training/saver.py", line 1286, in restore
    raise ValueError("Can't load save_path when it is None.")
ValueError: Can't load save_path when it is None.

jaideepmurkute avatar Jan 03 '21 00:01 jaideepmurkute