jl749 / YOLOv1

yolov1 implementation in pytorch (https://arxiv.org/pdf/1506.02640.pdf)
0 stars 0 forks source link

train, evaluate #3

Closed jl749 closed 2 years ago

jl749 commented 2 years ago

What does model.eval() do in pytorch? https://stackoverflow.com/questions/60018578/what-does-model-eval-do-in-pytorch

evaluate model:

model.eval()

with torch.no_grad():
    ...
    out_data = model(data)
    ...

training step:

...
model.train()
...
jl749 commented 2 years ago

(7, 7, 30) -- torch.Tensor::unsqueeze(0) --> (1, 7, 7, 30) (1, 7, 7) -- torch.Tensor::unsqueeze(-1) --> (1, 7, 7, 1)

jl749 commented 2 years ago

torch.permute()

>>> x = torch.randn(2, 3, 5)
>>> x.size()
torch.Size([2, 3, 5])
>>> torch.permute(x, (2, 0, 1)).size()
torch.Size([5, 2, 3])\
jl749 commented 2 years ago

propagate tensor with repeat()

batch size = 1
cell_indices = torch.arange(S).repeat(batch_size, S, 1).unsqueeze(-1)  # (1, 7, 7, 1)
result tensor ``` tensor([[[[0], [1], [2], [3], [4], [5], [6]], [[0], [1], [2], [3], [4], [5], [6]], [[0], [1], [2], [3], [4], [5], [6]], [[0], [1], [2], [3], [4], [5], [6]], [[0], [1], [2], [3], [4], [5], [6]], [[0], [1], [2], [3], [4], [5], [6]], [[0], [1], [2], [3], [4], [5], [6]]]]) ```

swap 1st 2nd indexes

cell_indices.permute(0, 2, 1, 3))
result tensor ``` tensor([[[[0], [0], [0], [0], [0], [0], [0]], [[1], [1], [1], [1], [1], [1], [1]], [[2], [2], [2], [2], [2], [2], [2]], [[3], [3], [3], [3], [3], [3], [3]], [[4], [4], [4], [4], [4], [4], [4]], [[5], [5], [5], [5], [5], [5], [5]], [[6], [6], [6], [6], [6], [6], [6]]]]) ```