mvasil / fashion-compatibility

Learning Type-Aware Embeddings for Fashion Compatibility
BSD 3-Clause "New" or "Revised" License
152 stars 42 forks source link

File "tripletnet.py", line 48, in forward x = x / norm.expand_as(x) RuntimeError: The expanded size of the tensor (64) must match the existing size (256) at non-singleton dimension 1. Target sizes: [256, 64]. Tensor sizes: [256] #27

Closed monajalal closed 3 years ago

monajalal commented 3 years ago
(fashcomp) [jalal@goku fashion-compatibility]$ python main.py --name test_baseline --learned --l2_embed --datadir ../../../data/fashion/
/scratch3/venv/fashcomp/lib/python3.8/site-packages/torchvision/transforms/transforms.py:310: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead.
  warnings.warn("The use of the transforms.Scale transform is deprecated, " +
  + Number of params: 3191808
<class 'torch.utils.data.dataloader.DataLoader'>
/scratch3/venv/fashcomp/lib/python3.8/site-packages/torch/nn/functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  /pytorch/c10/core/TensorImpl.h:1156.)
  return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
Traceback (most recent call last):
  File "main.py", line 324, in <module>
    main()    
  File "main.py", line 167, in main
    train(train_loader, tnet, criterion, optimizer, epoch)
  File "main.py", line 202, in train
    acc, loss_triplet, loss_mask, loss_embed, loss_vse, loss_sim_t, loss_sim_i = tnet(anchor, far, close)
  File "/scratch3/venv/fashcomp/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/scratch3/research/code/fashion/fashion-compatibility/tripletnet.py", line 147, in forward
    loss_sim_t, desc_x, desc_y, desc_z = self.text_forward(x, y, z)
  File "/scratch3/research/code/fashion/fashion-compatibility/tripletnet.py", line 112, in text_forward
    desc_x = self.text_branch(x.text)
  File "/scratch3/venv/fashcomp/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/scratch3/research/code/fashion/fashion-compatibility/tripletnet.py", line 48, in forward
    x = x / norm.expand_as(x)
RuntimeError: The expanded size of the tensor (64) must match the existing size (256) at non-singleton dimension 1.  Target sizes: [256, 64].  Tensor sizes: [256]
monajalal commented 3 years ago

fixed by this change in tripletnet.py

    def forward(self, x):
        x = self.fc1(x)
        x = self.fc2(x)

        # L2 normalize each feature vector
        ##norm = torch.norm(x, p=2, dim=1) + 1e-10
        ##x = x / norm.expand_as(x)
        x = torch.nn.functional.normalize(x, p=2.0, dim=1, eps=1e-10, out=None)
        return x