Open Jinjicheng opened 6 years ago
@Jinjicheng When I used another dataset (Mars) to train, the same error occured. The error would disappear if the parameter --batchid
was setted as another value (e.g. --batchid 5
), though I do not know the reason behind it.
i know it.For example,ids of train is 1041,batchid and batchimg is (16,4). Every batch has 16 id, but last batch has only 1 id,it is incompatible Triplet loss.
So that explains it. If ids = 1041 and batchid = 16, then because 1041/16 = 65...1, the number of batches is 66, where the first 65 batches have 16 ids and the last batch has only one id. However calculatig triplet loss needs two examples with different labels (ids). Thanks.
i run your code with new dataset(MSMT17),but it occured : [INFO] Making model... [INFO] Making loss... 1.000 CrossEntropy 1.000 Triplet [INFO] Epoch: 1 Learning rate: 2.00e-04 [INFO] [1/160] 65/66 [CrossEntropy: 9.6161][Triplet: 3.0369][Total: 12.6529]Traceback (most recen t call last): File "main.py", line 20, in
trainer.train()
File "G:\code2\MGN-pytorch-master\trainer.py", line 50, in train
loss.backward()
File "D:\Anaconda3\lib\site-packages\torch\tensor.py", line 93, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File "D:\Anaconda3\lib\site-packages\torch\autograd__init__.py", line 89, in backward
allow_unreachable=True) # allow_unreachable flag
RuntimeError: The expanded size of the tensor (1) must match the existing size (0) at non-singleton
dimension 0
how to solve it.