Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load pretrained weights to model. #51

Open
Namasivaayam-L opened this issue Jan 13, 2024 · 2 comments
Open

Unable to load pretrained weights to model. #51

Namasivaayam-L opened this issue Jan 13, 2024 · 2 comments

Comments

@Namasivaayam-L
Copy link

Namasivaayam-L commented Jan 13, 2024

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
Copy link

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

@Namasivaayam-L
Copy link
Author

Namasivaayam-L commented Aug 26, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants