Skip to content

Instantly share code, notes, and snippets.

@e96031413
Created September 11, 2020 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e96031413/addb24a8dab4a8ba405015a42a5a7d9e to your computer and use it in GitHub Desktop.
Save e96031413/addb24a8dab4a8ba405015a42a5a7d9e to your computer and use it in GitHub Desktop.
some pytorch and numpy usage
# torch.unsqueeze(1)可以新增shape
example:
x_val = torch.Size([10000, 28, 28])
x_val = x_val.unsqueeze(1)
# [out] torch.Size([10000, 1, 28, 28])
# the ToTensor method to convert images into PyTorch tensors.
# passed the transformer function to the dataset class. This way, data
# transformation will happen on-the-fly. This is a useful technique for large datasets that
# cannot be loaded into memory all at once.
img_t = torch.randn(3, 5, 5) # shape [channels, rows, columns]
batch_t = torch.randn(2, 3, 5, 5) # shape [batch, channels, rows, columns]
torch.Size([5, 5]), # shape ['rows', 'columns']
# np.reshape不改變原本的shape
# np.resize改變原本的shape
# np.hstack()、np.vstack()作concatenating arrays
# Broadcasting can add a scalar to a vector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment