From 3008d88222883c8691658b0a7833d07a1408d755 Mon Sep 17 00:00:00 2001 From: Liang Yi Date: Sat, 2 Jun 2018 23:14:26 +0800 Subject: [PATCH 01/15] minor refactoring for input size --- tutorials/01-basics/logistic_regression/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tutorials/01-basics/logistic_regression/main.py b/tutorials/01-basics/logistic_regression/main.py index a5b53b6c..c7eb378b 100644 --- a/tutorials/01-basics/logistic_regression/main.py +++ b/tutorials/01-basics/logistic_regression/main.py @@ -5,7 +5,7 @@ # Hyper-parameters -input_size = 784 +input_size = 28 * 28 # 784 num_classes = 10 num_epochs = 5 batch_size = 100 @@ -43,7 +43,7 @@ for epoch in range(num_epochs): for i, (images, labels) in enumerate(train_loader): # Reshape images to (batch_size, input_size) - images = images.reshape(-1, 28*28) + images = images.reshape(-1, input_size) # Forward pass outputs = model(images) @@ -64,7 +64,7 @@ correct = 0 total = 0 for images, labels in test_loader: - images = images.reshape(-1, 28*28) + images = images.reshape(-1, input_size) outputs = model(images) _, predicted = torch.max(outputs.data, 1) total += labels.size(0) From 7aac81272a127ec14be6370a34977f3c6fb5c58d Mon Sep 17 00:00:00 2001 From: Liang Yi Date: Sun, 3 Jun 2018 01:20:51 +0800 Subject: [PATCH 02/15] minor refactoring for batch size in deep residual network --- tutorials/02-intermediate/deep_residual_network/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tutorials/02-intermediate/deep_residual_network/main.py b/tutorials/02-intermediate/deep_residual_network/main.py index 2b2e43a7..1875a598 100644 --- a/tutorials/02-intermediate/deep_residual_network/main.py +++ b/tutorials/02-intermediate/deep_residual_network/main.py @@ -16,6 +16,7 @@ # Hyper-parameters num_epochs = 80 +batch_size = 100 learning_rate = 0.001 # Image preprocessing modules @@ -37,11 +38,11 @@ # Data loader train_loader = torch.utils.data.DataLoader(dataset=train_dataset, - batch_size=100, + batch_size=batch_size, shuffle=True) test_loader = torch.utils.data.DataLoader(dataset=test_dataset, - batch_size=100, + batch_size=batch_size, shuffle=False) # 3x3 convolution From e217e42e600ece714d047a6c7bcb098728cfa3ae Mon Sep 17 00:00:00 2001 From: Liang Yi Date: Sun, 3 Jun 2018 09:22:20 +0800 Subject: [PATCH 03/15] missing eval mode in recurrent neural network --- tutorials/02-intermediate/recurrent_neural_network/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tutorials/02-intermediate/recurrent_neural_network/main.py b/tutorials/02-intermediate/recurrent_neural_network/main.py index 9b8685ca..c138c5ad 100644 --- a/tutorials/02-intermediate/recurrent_neural_network/main.py +++ b/tutorials/02-intermediate/recurrent_neural_network/main.py @@ -85,6 +85,7 @@ def forward(self, x): .format(epoch+1, num_epochs, i+1, total_step, loss.item())) # Test the model +model.eval() with torch.no_grad(): correct = 0 total = 0 From ff803b749fe4d7b1128b2eec21d7effa0f4b244f Mon Sep 17 00:00:00 2001 From: mariuszrokita Date: Tue, 18 Sep 2018 13:15:29 +0200 Subject: [PATCH 04/15] Update main.py Fixed typos. --- tutorials/01-basics/pytorch_basics/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tutorials/01-basics/pytorch_basics/main.py b/tutorials/01-basics/pytorch_basics/main.py index 78b692a6..da41b0d0 100644 --- a/tutorials/01-basics/pytorch_basics/main.py +++ b/tutorials/01-basics/pytorch_basics/main.py @@ -98,7 +98,7 @@ # ================================================================== # -# 4. Input pipline # +# 4. Input pipeline # # ================================================================== # # Download and construct CIFAR-10 dataset. @@ -130,7 +130,7 @@ # ================================================================== # -# 5. Input pipline for custom dataset # +# 5. Input pipeline for custom dataset # # ================================================================== # # You should your build your custom dataset as below. @@ -186,4 +186,4 @@ def __len__(self): # Save and load only the model parameters (recommended). torch.save(resnet.state_dict(), 'params.ckpt') -resnet.load_state_dict(torch.load('params.ckpt')) \ No newline at end of file +resnet.load_state_dict(torch.load('params.ckpt')) From d25b573560d6a1a6295470b7a78e9f4dc142e7e5 Mon Sep 17 00:00:00 2001 From: Justin Shenk Date: Sat, 3 Nov 2018 20:08:10 +0100 Subject: [PATCH 05/15] Remove dollar-sign prompt from code blocks Improves sharing code without affecting readability --- .../03-advanced/image_captioning/README.md | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tutorials/03-advanced/image_captioning/README.md b/tutorials/03-advanced/image_captioning/README.md index eec7b284..409b62b4 100644 --- a/tutorials/03-advanced/image_captioning/README.md +++ b/tutorials/03-advanced/image_captioning/README.md @@ -16,41 +16,41 @@ In the test phase, the encoder part is almost same as the training phase. The on #### 1. Clone the repositories ```bash -$ git clone https://github.com/pdollar/coco.git -$ cd coco/PythonAPI/ -$ make -$ python setup.py build -$ python setup.py install -$ cd ../../ -$ git clone https://github.com/yunjey/pytorch-tutorial.git -$ cd pytorch-tutorial/tutorials/03-advanced/image_captioning/ +git clone https://github.com/pdollar/coco.git +cd coco/PythonAPI/ +make +python setup.py build +python setup.py install +cd ../../ +git clone https://github.com/yunjey/pytorch-tutorial.git +cd pytorch-tutorial/tutorials/03-advanced/image_captioning/ ``` #### 2. Download the dataset ```bash -$ pip install -r requirements.txt -$ chmod +x download.sh -$ ./download.sh +pip install -r requirements.txt +chmod +x download.sh +./download.sh ``` #### 3. Preprocessing ```bash -$ python build_vocab.py -$ python resize.py +python build_vocab.py +python resize.py ``` #### 4. Train the model ```bash -$ python train.py +python train.py ``` #### 5. Test the model ```bash -$ python sample.py --image='png/example.png' +python sample.py --image='png/example.png' ```
From 16691c00f83332267fcf180fd92e84ce1d1d915d Mon Sep 17 00:00:00 2001 From: Michael Hsu Date: Sun, 24 Feb 2019 10:02:07 +0800 Subject: [PATCH 06/15] Let sample.py can generate caption for gray image. The sample.py cannot be used to generate caption for gray image.In the data_loader.py, all of the images have been converted to 'RGB' format. But when generating captions using sample.py for single image, this conversion is missed. So for gray image, it will have such RuntimeError: Given groups=1, weight of size [64, 3, 7, 7], expected input[1, 1, 224, 224] to have 3 channels, but got 1 channels instead. --- tutorials/03-advanced/image_captioning/sample.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/03-advanced/image_captioning/sample.py b/tutorials/03-advanced/image_captioning/sample.py index 23e07efd..b41cc6f6 100644 --- a/tutorials/03-advanced/image_captioning/sample.py +++ b/tutorials/03-advanced/image_captioning/sample.py @@ -14,7 +14,7 @@ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') def load_image(image_path, transform=None): - image = Image.open(image_path) + image = Image.open(image_path).convert('RGB') image = image.resize([224, 224], Image.LANCZOS) if transform is not None: @@ -78,4 +78,4 @@ def main(args): parser.add_argument('--hidden_size', type=int , default=512, help='dimension of lstm hidden states') parser.add_argument('--num_layers', type=int , default=1, help='number of layers in lstm') args = parser.parse_args() - main(args) \ No newline at end of file + main(args) From b5793737c61d30decba8b42ce05e3b77b6ef802b Mon Sep 17 00:00:00 2001 From: Mohammad Hasan Date: Wed, 13 Mar 2019 22:23:53 +0600 Subject: [PATCH 07/15] Fixed Test error when encoder(image). When we load an image for the sample, we have to make sure that the image has three color channel (RGB) because it might be grayscale. So we should convert it for sampling. --- tutorials/03-advanced/image_captioning/sample.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/03-advanced/image_captioning/sample.py b/tutorials/03-advanced/image_captioning/sample.py index 23e07efd..b41cc6f6 100644 --- a/tutorials/03-advanced/image_captioning/sample.py +++ b/tutorials/03-advanced/image_captioning/sample.py @@ -14,7 +14,7 @@ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') def load_image(image_path, transform=None): - image = Image.open(image_path) + image = Image.open(image_path).convert('RGB') image = image.resize([224, 224], Image.LANCZOS) if transform is not None: @@ -78,4 +78,4 @@ def main(args): parser.add_argument('--hidden_size', type=int , default=512, help='dimension of lstm hidden states') parser.add_argument('--num_layers', type=int , default=1, help='number of layers in lstm') args = parser.parse_args() - main(args) \ No newline at end of file + main(args) From dd297a130785320e5a82d5a05f10c58ff39956a8 Mon Sep 17 00:00:00 2001 From: qy-yang Date: Tue, 27 Aug 2019 17:31:42 +0800 Subject: [PATCH 08/15] fix #187 Typos in language model line 79 and generative_adversarial_network line 25-28 --- tutorials/02-intermediate/language_model/main.py | 2 +- .../03-advanced/generative_adversarial_network/main.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tutorials/02-intermediate/language_model/main.py b/tutorials/02-intermediate/language_model/main.py index 3c03db03..ef135bb7 100644 --- a/tutorials/02-intermediate/language_model/main.py +++ b/tutorials/02-intermediate/language_model/main.py @@ -76,7 +76,7 @@ def detach(states): loss = criterion(outputs, targets.reshape(-1)) # Backward and optimize - model.zero_grad() + optimizer.zero_grad() loss.backward() clip_grad_norm_(model.parameters(), 0.5) optimizer.step() diff --git a/tutorials/03-advanced/generative_adversarial_network/main.py b/tutorials/03-advanced/generative_adversarial_network/main.py index 34f41274..c2062cf3 100644 --- a/tutorials/03-advanced/generative_adversarial_network/main.py +++ b/tutorials/03-advanced/generative_adversarial_network/main.py @@ -22,10 +22,14 @@ os.makedirs(sample_dir) # Image processing +# transform = transforms.Compose([ +# transforms.ToTensor(), +# transforms.Normalize(mean=(0.5, 0.5, 0.5), # 3 for RGB channels +# std=(0.5, 0.5, 0.5))]) transform = transforms.Compose([ transforms.ToTensor(), - transforms.Normalize(mean=(0.5, 0.5, 0.5), # 3 for RGB channels - std=(0.5, 0.5, 0.5))]) + transforms.Normalize(mean=[0.5], # 1 for greyscale channels + std=[0.5])]) # MNIST dataset mnist = torchvision.datasets.MNIST(root='../../data/', From 25b2685d5eae596e5a627c757fd1e2440fc1a72f Mon Sep 17 00:00:00 2001 From: Haofan Wang Date: Sun, 15 Sep 2019 14:12:04 -0500 Subject: [PATCH 09/15] Update default path --- tutorials/03-advanced/image_captioning/sample.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tutorials/03-advanced/image_captioning/sample.py b/tutorials/03-advanced/image_captioning/sample.py index 23e07efd..b7a4dd1b 100644 --- a/tutorials/03-advanced/image_captioning/sample.py +++ b/tutorials/03-advanced/image_captioning/sample.py @@ -69,8 +69,8 @@ def main(args): if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--image', type=str, required=True, help='input image for generating caption') - parser.add_argument('--encoder_path', type=str, default='models/encoder-2-1000.ckpt', help='path for trained encoder') - parser.add_argument('--decoder_path', type=str, default='models/decoder-2-1000.ckpt', help='path for trained decoder') + parser.add_argument('--encoder_path', type=str, default='models/encoder-5-3000.pkl', help='path for trained encoder') + parser.add_argument('--decoder_path', type=str, default='models/decoder-5-3000.pkl', help='path for trained decoder') parser.add_argument('--vocab_path', type=str, default='data/vocab.pkl', help='path for vocabulary wrapper') # Model parameters (should be same as paramters in train.py) @@ -78,4 +78,4 @@ def main(args): parser.add_argument('--hidden_size', type=int , default=512, help='dimension of lstm hidden states') parser.add_argument('--num_layers', type=int , default=1, help='number of layers in lstm') args = parser.parse_args() - main(args) \ No newline at end of file + main(args) From 64c733001b8facfeb793cd1dbea34f4d46f4d147 Mon Sep 17 00:00:00 2001 From: Yunjey Choi Date: Mon, 27 Apr 2020 11:43:13 +0900 Subject: [PATCH 10/15] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 776b8394..272fc44b 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,6 @@ This repository provides tutorial code for deep learning researchers to learn [P * [TensorBoard in PyTorch](https://github.com/yunjey/pytorch-tutorial/tree/master/tutorials/04-utils/tensorboard) -
## Getting Started @@ -52,6 +51,4 @@ $ python main.py
- -## Author -Yunjey Choi/ [@yunjey](https://github.com/yunjey) +If you are interested in generative models, please check our recent work [StarGAN v2](https://github.com/clovaai/stargan-v2). From 825b423f4ce40901e7556d7f8b77588cad6d6673 Mon Sep 17 00:00:00 2001 From: Yunjey Choi Date: Mon, 27 Apr 2020 11:44:17 +0900 Subject: [PATCH 11/15] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 272fc44b..104ffaaf 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -------------------------------------------------------------------------------- -This repository provides tutorial code for deep learning researchers to learn [PyTorch](https://github.com/pytorch/pytorch). In the tutorial, most of the models were implemented with less than 30 lines of code. Before starting this tutorial, it is recommended to finish [Official Pytorch Tutorial](http://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html). +This repository provides tutorial code for deep learning researchers to learn [PyTorch](https://github.com/pytorch/pytorch). In the tutorial, most of the models were implemented with less than 30 lines of code. Before starting this tutorial, it is recommended to finish [Official Pytorch Tutorial](http://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html). If you are also interested in generative models, please check our recent work [StarGAN v2](https://github.com/clovaai/stargan-v2).
@@ -49,6 +49,4 @@ $ python main.py -
-If you are interested in generative models, please check our recent work [StarGAN v2](https://github.com/clovaai/stargan-v2). From 2032bb3501e85d47f8c5e09df135dd02c32a162c Mon Sep 17 00:00:00 2001 From: Yunjey Choi Date: Mon, 1 Jun 2020 12:56:16 +0900 Subject: [PATCH 12/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 104ffaaf..59ac3300 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -------------------------------------------------------------------------------- -This repository provides tutorial code for deep learning researchers to learn [PyTorch](https://github.com/pytorch/pytorch). In the tutorial, most of the models were implemented with less than 30 lines of code. Before starting this tutorial, it is recommended to finish [Official Pytorch Tutorial](http://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html). If you are also interested in generative models, please check our recent work [StarGAN v2](https://github.com/clovaai/stargan-v2). +This repository provides tutorial code for deep learning researchers to learn [PyTorch](https://github.com/pytorch/pytorch). In the tutorial, most of the models were implemented with less than 30 lines of code. Before starting this tutorial, it is recommended to finish [Official Pytorch Tutorial](http://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html).
From 272b8f27afd9741239e8cb61bd2b89a850abc911 Mon Sep 17 00:00:00 2001 From: Yunjey Choi Date: Tue, 16 Jun 2020 21:24:41 +0900 Subject: [PATCH 13/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 59ac3300..bbb03327 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -------------------------------------------------------------------------------- -This repository provides tutorial code for deep learning researchers to learn [PyTorch](https://github.com/pytorch/pytorch). In the tutorial, most of the models were implemented with less than 30 lines of code. Before starting this tutorial, it is recommended to finish [Official Pytorch Tutorial](http://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html). +This repository provides tutorial code for deep learning researchers to learn [PyTorch](https://github.com/pytorch/pytorch). In the tutorial, most of the models were implemented with less than 30 lines of code. Before starting this tutorial, it is recommended to finish [Official Pytorch Tutorial](http://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html). If you are also interested in generative adversarial networks, check out recent work, [TUNIT](https://github.com/clovaai/tunit).
From 0fbb8b60c145efb67ff00940ffed403a66ef2d87 Mon Sep 17 00:00:00 2001 From: Yunjey Choi Date: Tue, 16 Jun 2020 21:25:07 +0900 Subject: [PATCH 14/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bbb03327..051e94f1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -------------------------------------------------------------------------------- -This repository provides tutorial code for deep learning researchers to learn [PyTorch](https://github.com/pytorch/pytorch). In the tutorial, most of the models were implemented with less than 30 lines of code. Before starting this tutorial, it is recommended to finish [Official Pytorch Tutorial](http://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html). If you are also interested in generative adversarial networks, check out recent work, [TUNIT](https://github.com/clovaai/tunit). +This repository provides tutorial code for deep learning researchers to learn [PyTorch](https://github.com/pytorch/pytorch). In the tutorial, most of the models were implemented with less than 30 lines of code. Before starting this tutorial, it is recommended to finish [Official Pytorch Tutorial](http://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html). If you are also interested in generative adversarial networks, check out our recent work, [TUNIT](https://github.com/clovaai/tunit).
From 0500d3df5a2a8080ccfccbc00aca0eacc21818db Mon Sep 17 00:00:00 2001 From: Yunjey Choi Date: Mon, 6 Jul 2020 12:36:38 +0900 Subject: [PATCH 15/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 051e94f1..59ac3300 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ -------------------------------------------------------------------------------- -This repository provides tutorial code for deep learning researchers to learn [PyTorch](https://github.com/pytorch/pytorch). In the tutorial, most of the models were implemented with less than 30 lines of code. Before starting this tutorial, it is recommended to finish [Official Pytorch Tutorial](http://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html). If you are also interested in generative adversarial networks, check out our recent work, [TUNIT](https://github.com/clovaai/tunit). +This repository provides tutorial code for deep learning researchers to learn [PyTorch](https://github.com/pytorch/pytorch). In the tutorial, most of the models were implemented with less than 30 lines of code. Before starting this tutorial, it is recommended to finish [Official Pytorch Tutorial](http://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html).