0

I try to do transfer learning to efficientnet in tensorflow. I want to use noisy-student checkpoints instead of imagenet weights:

model = EfficientNetB3(weights='noisy_student_efficientnet-b3', include_top=False, 
input_shape=(IMAGE_SIZE,IMAGE_SIZE,3))

I download it from here in section: 2. Using Pretrained EfficientNet Checkpoints

and I get an error:

    The model is  EfficientNetB3
Traceback (most recent call last):
  File "image_retraining.py", line 23, in <module>
    model_base = EfficientNetB3(weights='/home/retrain_models/etty/noisy_student_efficientnet-b3', include_top=False, 
  File "/usr/local/lib/python3.8/dist-packages/keras/applications/efficientnet.py", line 614, in EfficientNetB3
    return EfficientNet(
  File "/usr/local/lib/python3.8/dist-packages/keras/applications/efficientnet.py", line 414, in EfficientNet
    model.load_weights(weights)
  File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/usr/local/lib/python3.8/dist-packages/h5py/_hl/files.py", line 507, in __init__
    fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr)
  File "/usr/local/lib/python3.8/dist-packages/h5py/_hl/files.py", line 220, in make_fid
    fid = h5f.open(name, flags, fapl=fapl)
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py/h5f.pyx", line 106, in h5py.h5f.open
IsADirectoryError: [Errno 21] Unable to open file (file read failed: time = Sun Mar 13 11:57:14 2022
, filename = '/home/retrain_models/etty/noisy_student_efficientnet-b3', file descriptor = 51, errno = 21, error message = 'Is a directory', buf = 0x7ffd67594fb8, total read size = 8, bytes this sub-read = 8, bytes actually read = 18446744073709551615, offset = 0)
Exception ignored in: <function Pool.__del__ at 0x7f9e2cbf3dc0>
Traceback (most recent call last):
  File "/usr/lib/python3.8/multiprocessing/pool.py", line 268, in __del__
  File "/usr/lib/python3.8/multiprocessing/queues.py", line 362, in put
AttributeError: 'NoneType' object has no attribute 'dumps'

I tried to download it again, but it was not change. Using Tensorflow version: 2.7.0

I whould be very happy to get your advices. Thanks.

MT0
  • 143,790
  • 11
  • 59
  • 117
Shirly
  • 38
  • 6

1 Answers1

0

So here is the full answer, just follow that instructions:

  1. Take the desire updated weights from here. you need to scroll down the page slightly, and you will see there a table of weights, just press on the relevant link from you, and it will be download for you.

  2. Extract the directory you downloaded

  3. You should download the script: efficientnet_weight_update_util.py from here

  4. Put these 3 files from step 2:

    model.ckpt.data-00000-of-00001, model.ckpt.index, model.ckpt.meta

    at the same directory with the script from step 3.

  5. Run the script in order to convert the weights to h5 format: run it with that command:

    python3 efficientnet_weight_update_util.py --model b3 --notop --ckpt efficientnet-b3/model.ckpt --o efficientnetb3_notop.h5

    I wrote b3 just for example, you will write b1....b7 for param --ckpt enter the path for the wheights. notice to enter: model.ckpt without the extensions.

  6. Now everything is ready, just load your model and then:

    model_base.load_weights('efficientnetb3_notop.h5')

Shirly
  • 38
  • 6