-
Notifications
You must be signed in to change notification settings - Fork 37
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
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn #18
Comments
Hi! In this case, the issue is here: model_hybrid = torchvision.models.resnet18(pretrained=True)
for param in model_hybrid.parameters():
param.requires_grad = False
if quantum:
model_hybrid.fc = Quantumnet()
elif classical_model == '512_2':
model_hybrid.fc = nn.Linear(512, 2)
elif classical_model == '512_nq_2':
model_hybrid.fc = nn.Sequential(nn.Linear(512, n_qubits), torch.nn.ReLU(), nn.Linear(n_qubits, 2))
elif classical_model == '551_512_2':
model_hybrid.fc = nn.Sequential(nn.Linear(512, 512), torch.nn.ReLU(), nn.Linear(512, 2))
# Use CUDA or CPU according to the "device" object.
model_hybrid = model_hybrid.to(device) This cell is built taking into account the resnet model. For example, the attribute "fc" does not exist in the model you propose. So a more detailed study would have to be done to change to another one. It would be great to see the results with other models 😄 |
Hi @sleepingcat4, to complement @KetpuntoG's answer, The attributes in ResNet and MobileNetV2 are different. You can check the source code to see this. Let us know if this helps! |
thank you for the comments. @CatalinaAlbornoz @KetpuntoG I was aware of the differences between architecture but I was not sure which particular code/code cell was causing the error. I am not sure, whether it was the I will keep you guys updated and maybe able to share results with you as well after a few days. |
Yes please let us know how it goes @sleepingcat4 ! |
Thanks for sharing such oustanding tutorials on Transfer-learning and Quantum Circuits. I was experimenting the code with MobileNet V2. By default the notebook uses Resnet18. But, I thought to use MobileNet V2 for experimentation. Unfortunately, I am receiving this error. Can you please help me in revolving this error?
Code I changed:
Error received:
Notebook used:
c2q_transfer_learning_ants_bees.ipynb
The text was updated successfully, but these errors were encountered: