Visual-Behavior / detr-tensorflow

Tensorflow implementation of DETR : Object Detection with Transformers
MIT License
168 stars 53 forks source link

Unable to load pretrained weights to model. #51

Open Namasivaayam-L opened 9 months ago

Namasivaayam-L commented 9 months ago

I have referred these existing issues and still my issue persists: #48 #40 (tried to copy the code from the weights.txt provided in the issue)

I request you guys to take a look.

CODE: from detr_tf.networks.detr import get_detr_model detr = get_detr_model(config, include_top=False, nb_class=10, weights="detr") detr.summary()

ERROR: Load weights from weights/detr/detr.ckpt 2024-01-13 12:06:41.142705: W tensorflow/core/util/tensor_slice_reader.cc:98] Could not open weights/detr/detr.ckpt: DATA_LOSS: not an sstable (bad magic number): perhaps your file is in a different file format and you need to use a different restore operator?

STACK TREE:

ValueError Traceback (most recent call last) Cell In[6], line 6 1 from detr_tf.networks.detr import get_detr_model ----> 6 detr = get_detr_model(config, include_top=False, nb_class=10, weights="detr") 7 detr.summary()

File ~/Documents/Project/detr-tensorflow/notebooks/../detr_tf/networks/detr.py:139, in get_detr_model(config, include_top, nb_class, weights, tf_backbone, num_decoder_layers, num_encoder_layers) 136 detr = DETR(num_decoder_layers=num_decoder_layers, num_encoder_layers=num_encoder_layers) 138 if weights is not None: --> 139 load_weights(detr, weights) 141 image_input = tf.keras.Input((None, None, 3)) 143 # Backbone

File ~/Documents/Project/detr-tensorflow/notebooks/../detr_tf/networks/weights.py:35, in load_weights(model, weights) 33 open(os.path.join(wdir, fname), 'wb').write(r.content) 34 print("Load weights from", os.path.join(wdir, f"{weights}.ckpt")) ---> 35 l = model.load_weights(os.path.join(wdir, f"{weights}.ckpt")) 36 l.expect_partial() 37 else:

File /usr/local/lib/python3.10/dist-packages/keras/src/utils/traceback_utils.py:70, in filter_traceback..error_handler(*args, **kwargs) 67 filtered_tb = _process_traceback_frames(e.traceback) 68 # To get the full stack trace, call: 69 # tf.debugging.disable_traceback_filtering() ---> 70 raise e.with_traceback(filtered_tb) from None 71 finally: 72 del filtered_tb

File /usr/local/lib/python3.10/dist-packages/keras/src/saving/legacy/save.py:480, in load_weights(model, filepath, by_name, skip_mismatch, options) 475 raise ImportError( 476 "load_weights requires h5py package when loading weights " 477 "from HDF5. Try installing h5py." 478 ) 479 if not model._is_graph_network and not model.built: --> 480 raise ValueError( 481 "Unable to load weights saved in HDF5 format into a " 482 "subclassed Model which has not created its variables yet. " 483 "Call the Model first, then load the weights." 484 ) 485 model._assert_weights_created() 486 with h5py.File(filepath, "r") as f:

ValueError: Unable to load weights saved in HDF5 format into a subclassed Model which has not created its variables yet. Call the Model first, then load the weights.

These are the checkpoint files that got downloaded: image I even downloaded the detr.ckpt using this link: https://storage.googleapis.com/visualbehavior-publicweights/detr/detr.ckpt image

I have all the files as default from the repository except I am using a custom dataset. But obviously it has nothing to do with my problem here. Thank you.

catalysts-higher commented 2 months ago

hi, Namasivaayam, can you share the download weights files? the original links seem invalid now. thank you!

Namasivaayam-L commented 2 months ago

I'm not sure, I have it... I'll chk my hdd and let you know by tonight.

On Mon, Aug 26, 2024, 1:10 PM YueqiLuoCata @.***> wrote:

hi, Namasivaayam, can you share the download weights files? the original links seem invalid now. thank you!

— Reply to this email directly, view it on GitHub https://github.com/Visual-Behavior/detr-tensorflow/issues/51#issuecomment-2309550393, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT7AASWSTITKAGPW3EQN5ITZTLLVPAVCNFSM6AAAAABNDONL6OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBZGU2TAMZZGM . You are receiving this because you authored the thread.Message ID: @.***>