UnboundLocalError: local variable 'loss' referenced before assignment
I was trying to test an image using the train-image-inference.ipynb file. But in the last block of code, I am getting an error.
ValueError Traceback (most recent call last)
7 frames /usr/local/lib/python3.7/dist-packages/sklearn/metrics/pairwise.py in check_pairwise_arrays(X, Y, precomputed, dtype, accept_sparse, force_all_finite, copy) 153 raise ValueError("Incompatible dimension for X and Y matrices: " 154 "X.shape[1] == %d while Y.shape[1] == %d" % ( --> 155 X.shape[1], Y.shape[1])) 156 157 return X, Y
ValueError: Incompatible dimension for X and Y matrices: X.shape[1] == 65536 while Y.shape[1] == 262144
Please help me how to solve this issue
Hi! most probably the dimensions of your image are not same. You would need to resize them. This is due to assumption int the tutorial that all the images have shape of (512, 512). For images of different size, you would need different embeddings dimensions.
Hi! I have the same problem, however changing the dimensions of the image doesn't fix the problem.
`Setting Seed for the run, seed = 42
------------ Creating Dataset ------------
------------ Dataset Created ------------
------------ Creating DataLoader ------------
------------ Dataloader Cretead ------------
MSELoss()
GPU Availaible moving models to GPU
------------ Training started ------------
0%| | 0/30 [00:00<?, ?it/s]
Traceback (most recent call last):
File "E:/Work/UNI/Third_year_first_semester/Szoftver tervezes/Projekt/Image recognition repos/image_similarity/image_similarity-master/image_similarity/torch_train.py", line 79, in
Process finished with exit code 1`
Have you written in the torch_train.py code. If yes then it should work fine.
loss_fn = nn.MSELoss()
Unfortunately it does not. The train-image-similarity.ipynb also has this problem.
I'm still perplexed. It should run as I had tested this code (long time ago) and it ran fine. Even the ipynb has the output.
https://github.com/oke-aditya/image_similarity/blob/master/image_similarity/train-image-similarity.ipynb
Can you share a reproducible script over colab so that I can debug?
I think you just use a small size images for test. So you can modify drop_last from True to False in torch_train.py.
train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=config.TRAIN_BATCH_SIZE, shuffle=True, drop_last=False)