Skip to content
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

train, evaluate #3

Closed
jl749 opened this issue Jan 14, 2022 · 4 comments
Closed

train, evaluate #3

jl749 opened this issue Jan 14, 2022 · 4 comments

Comments

@jl749
Copy link
Owner

jl749 commented Jan 14, 2022

No description provided.

@jl749
Copy link
Owner Author

jl749 commented Jan 14, 2022

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
Copy link
Owner Author

jl749 commented Jan 14, 2022

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

@jl749
Copy link
Owner Author

jl749 commented Jan 14, 2022

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
Copy link
Owner Author

jl749 commented Jan 14, 2022

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]]]])

jl749 added a commit that referenced this issue Jan 14, 2022
@jl749 jl749 closed this as completed Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant