├── README.md
├── data
├── combine_A_and_B.py
├── diabetes.csv.gz
├── downloadCelebA.sh
├── download_cyclegan_dataset.sh
├── download_cyclegan_datasetTrain.sh
├── download_pix2pix_dataset.sh
├── lsun
│ ├── README.md
│ ├── category_indices.txt
│ ├── data.py
│ └── download.py
├── make_dataset_aligned.py
├── names_test.csv.gz
├── names_train.csv.gz
├── setting_up_script.sh
└── shakespeare.txt.gz
├── logo
└── pytorch_logo.png
├── slides
├── Lecture 02_ Linear Model.pptx
├── Lecture 03_ Gradient Descent.pptx
├── Lecture 04_ Back-propagation and PyTorch autograd.pptx
├── Lecture 05_ Linear regression in PyTorch way.pptx
├── Lecture 06_ Logistic Regression.pptx
├── Lecture 07_ Wide _ Deep.pptx
├── Lecture 08_ DataLoader.pptx
├── Lecture 09_ Softmax Classifier.pptx
├── Lecture 10_ Basic CNN.pptx
├── Lecture 11_ Advanced CNN.pptx
├── Lecture 12_ RNN.pdf
├── Lecture 12_ RNN.pptx
├── Lecture 13_ RNN II.pdf
├── Lecture 13_ RNN II.pptx
├── Lecture 14_ Seq2Seq.pptx
├── Lecture 15_ NSML_ Smartest ML Platform.pptx
├── P-Epilogue_ What_s the next_.pptx
└── template.pptx
└── tutorials
├── 01-basics
├── Back_propagration
│ └── main.py
├── DataLoader
│ ├── main.py
│ └── main_logistic.py
├── Feedforward_neural_network
│ ├── main-gpu.py
│ └── main.py
├── Gradient_Descent
│ └── main.py
├── Linear_Model
│ └── main.py
├── Linear_regression
│ ├── lr.py
│ └── main.py
├── Logistic_regression
│ └── main.py
├── Softmax_Classifier
│ ├── main.py
│ └── main_mnist.py
├── Wide_Deep
│ └── main.py
└── pytorch_basics
│ └── main.py
├── 02-intermediate
├── bidirectional_recurrent_neural_network
│ ├── main-gpu.py
│ └── main.py
├── convolutional_neural_network
│ ├── main-gpu.py
│ └── main.py
├── deep_residual_network
│ ├── main-gpu.py
│ └── main.py
├── generative_adversarial_network
│ └── main.py
├── language_model
│ ├── data
│ │ └── train.txt
│ ├── data_utils.py
│ ├── main-gpu.py
│ └── main.py
└── recurrent_neural_network
│ ├── main-gpu.py
│ └── main.py
├── 03-advanced
├── deep_convolutional_gan
│ ├── README.md
│ ├── data_loader.py
│ ├── download.sh
│ ├── main.py
│ ├── model.py
│ ├── png
│ │ ├── dcgan.png
│ │ ├── sample1.png
│ │ └── sample2.png
│ ├── requirements.txt
│ └── solver.py
├── image_captioning
│ ├── README.md
│ ├── build_vocab.py
│ ├── data_loader.py
│ ├── download.sh
│ ├── model.py
│ ├── png
│ │ ├── example.png
│ │ ├── image_captioning.png
│ │ └── model.png
│ ├── requirements.txt
│ ├── resize.py
│ ├── sample.py
│ └── train.py
├── neural_style_transfer
│ ├── README.md
│ ├── main.py
│ ├── png
│ │ ├── content.png
│ │ ├── neural_style.png
│ │ ├── neural_style2.png
│ │ ├── style.png
│ │ ├── style2.png
│ │ ├── style3.png
│ │ └── style4.png
│ └── requirements.txt
└── variational_auto_encoder
│ ├── README.md
│ ├── main.py
│ ├── png
│ ├── real.png
│ ├── reconst.png
│ └── vae.png
│ └── requirements.txt
└── 04-utils
└── tensorboard
├── README.md
├── gif
├── g
└── tensorboard.gif
├── logger.py
├── main.py
└── requirements.txt
/README.md:
--------------------------------------------------------------------------------
1 |

2 |
3 | --------------------------------------------------------------------------------
4 |
5 | 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).
6 |
7 |
8 |
9 |
10 | ## Table of Contents
11 | #### PPTs
12 | * [PyTorchZeroToAll](https://drive.google.com/drive/folders/0B41Zbb4c8HVyUndGdGdJSXd5d3M)
13 | #### Videos
14 | * [PyTorchZeroToAll-lecture1~lecture4-Chinese version](https://youtu.be/MuyUFqJf_Ug)
15 | #### Install
16 | * [PyTorch install]
17 | ## Getting Installed for OSX pip 3.6 without coda
18 | ```bash
19 | $ pip3 install http://download.pytorch.org/whl/torch-0.3.1-cp36-cp36m-macosx_10_7_x86_64.whl
20 | $ pip3 install torchvision
21 | ```
22 | ## Getting Installed for Linux pip 3.5 with coda9
23 | ```bash
24 | $ pip3 install http://download.pytorch.org/whl/cu90/torch-0.3.1-cp35-cp35m-linux_x86_64.whl
25 | $ pip3 install torchvision
26 | ```
27 | #### 1. Basics
28 | * [Lecture2:Linear Model](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/01-basics/Linear_Model/main.py)
29 | * [Lecture3:Gradient_Descent](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/01-basics/Gradient_Descent/main.py)
30 | * [Lecture4:Back_propagration](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/01-basics/Back_propagration/main.py)
31 | * [Lecture5:Linear_regression](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/01-basics/Linear_regression/main.py)
32 | * [Lecture6:Logistic_regression](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/01-basics/Logistic_regression/main.py)
33 | * [Lecture7:Wide_Deep](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/01-basics/Wide_Deep/main.py)
34 | * [Lecture8:DataLoader](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/01-basics/DataLoader/main.py)
35 | * [Lecture8:DataLoader_logistic](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/01-basics/DataLoader/main_logistic.py)
36 | * [Lecture9:Softmax_Classifier](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/01-basics/Softmax_Classifier/main.py)
37 | * [Lecture9:Softmax_Classifier_mnist](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/01-basics/Softmax_Classifier/main_mnist.py)
38 |
39 | #### 2. Intermediate
40 | * [Convolutional Neural Network](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/02-intermediate/convolutional_neural_network/main.py#L33-L53)
41 | * [Deep Residual Network](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/02-intermediate/deep_residual_network/main.py#L67-L103)
42 | * [Recurrent Neural Network](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/02-intermediate/recurrent_neural_network/main.py#L38-L56)
43 | * [Bidirectional Recurrent Neural Network](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/02-intermediate/bidirectional_recurrent_neural_network/main.py#L38-L57)
44 | * [Language Model (RNN-LM)](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/02-intermediate/language_model/main.py#L28-L53)
45 | * [Generative Adversarial Network](https://github.com/Tim810306/PytorchTutorial/blob/master/tutorials/02-intermediate/generative_adversarial_network/main.py#L34-L50)
46 |
47 | #### 3. Advanced
48 | * [Image Captioning (CNN-RNN)](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/03-advanced/image_captioning)
49 | * [Deep Convolutional GAN (DCGAN)](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/03-advanced/deep_convolutional_gan)
50 | * [Variational Auto-Encoder](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/03-advanced/variational_auto_encoder)
51 | * [Neural Style Transfer](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/03-advanced/neural_style_transfer)
52 |
53 | #### 4. Utilities
54 | * [TensorBoard in PyTorch](https://github.com/Tim810306/PytorchTutorial/tree/master/tutorials/04-utils/tensorboard)
55 |
56 |
57 |
58 |
59 | ## Getting Started
60 | ```bash
61 | $ git clone https://github.com/Tim810306/PytorchTutorial.git
62 | $ cd PytorchTutorial/tutorials/project_path
63 | $ python main.py # cpu version
64 | $ python main-gpu.py # gpu version
65 | $ python main_XXX.py # execute XXX for cpu version
66 | ```
67 |
68 |
69 |
70 | ## Dependencies
71 | * [Python 2.7 or 3.5](https://www.continuum.io/downloads)
72 | * [PyTorch 0.1.12](http://pytorch.org/)
73 |
74 |
75 |
76 |
77 |
78 |
79 | ## Author
80 | Cheng Yu Ting/ [@Tim810306](https://github.com/Tim810306)
--------------------------------------------------------------------------------
/data/combine_A_and_B.py:
--------------------------------------------------------------------------------
1 | import os
2 | import numpy as np
3 | import cv2
4 | import argparse
5 |
6 | parser = argparse.ArgumentParser('create image pairs')
7 | parser.add_argument('--fold_A', dest='fold_A', help='input directory for image A', type=str, default='../dataset/50kshoes_edges')
8 | parser.add_argument('--fold_B', dest='fold_B', help='input directory for image B', type=str, default='../dataset/50kshoes_jpg')
9 | parser.add_argument('--fold_AB', dest='fold_AB', help='output directory', type=str, default='../dataset/test_AB')
10 | parser.add_argument('--num_imgs', dest='num_imgs', help='number of images',type=int, default=1000000)
11 | parser.add_argument('--use_AB', dest='use_AB', help='if true: (0001_A, 0001_B) to (0001_AB)',action='store_true')
12 | args = parser.parse_args()
13 |
14 | for arg in vars(args):
15 | print('[%s] = ' % arg, getattr(args, arg))
16 |
17 | splits = os.listdir(args.fold_A)
18 |
19 | for sp in splits:
20 | img_fold_A = os.path.join(args.fold_A, sp)
21 | img_fold_B = os.path.join(args.fold_B, sp)
22 | img_list = os.listdir(img_fold_A)
23 | if args.use_AB:
24 | img_list = [img_path for img_path in img_list if '_A.' in img_path]
25 |
26 | num_imgs = min(args.num_imgs, len(img_list))
27 | print('split = %s, use %d/%d images' % (sp, num_imgs, len(img_list)))
28 | img_fold_AB = os.path.join(args.fold_AB, sp)
29 | if not os.path.isdir(img_fold_AB):
30 | os.makedirs(img_fold_AB)
31 | print('split = %s, number of images = %d' % (sp, num_imgs))
32 | for n in range(num_imgs):
33 | name_A = img_list[n]
34 | path_A = os.path.join(img_fold_A, name_A)
35 | if args.use_AB:
36 | name_B = name_A.replace('_A.', '_B.')
37 | else:
38 | name_B = name_A
39 | path_B = os.path.join(img_fold_B, name_B)
40 | if os.path.isfile(path_A) and os.path.isfile(path_B):
41 | name_AB = name_A
42 | if args.use_AB:
43 | name_AB = name_AB.replace('_A.', '.') # remove _A
44 | path_AB = os.path.join(img_fold_AB, name_AB)
45 | im_A = cv2.imread(path_A, cv2.CV_LOAD_IMAGE_COLOR)
46 | im_B = cv2.imread(path_B, cv2.CV_LOAD_IMAGE_COLOR)
47 | im_AB = np.concatenate([im_A, im_B], 1)
48 | cv2.imwrite(path_AB, im_AB)
49 |
--------------------------------------------------------------------------------
/data/diabetes.csv.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Tim810306/PytorchTutorial/a14fe66a454b40108fbe703407971026d83d943f/data/diabetes.csv.gz
--------------------------------------------------------------------------------
/data/downloadCelebA.sh:
--------------------------------------------------------------------------------
1 | # CelebA images
2 | URL=https://www.dropbox.com/s/3e5cmqgplchz85o/CelebA_nocrop.zip?dl=0
3 | ZIP_FILE=./data/CelebA_nocrop.zip
4 | mkdir -p ./data/
5 | wget -N $URL -O $ZIP_FILE
6 | unzip $ZIP_FILE -d ./data/
7 | rm $ZIP_FILE
8 |
9 | # CelebA attribute labels
10 | URL=https://www.dropbox.com/s/auexdy98c6g7y25/list_attr_celeba.zip?dl=0
11 | ZIP_FILE=./data/list_attr_celeba.zip
12 | wget -N $URL -O $ZIP_FILE
13 | unzip $ZIP_FILE -d ./data/
14 | rm $ZIP_FILE
15 |
--------------------------------------------------------------------------------
/data/download_cyclegan_dataset.sh:
--------------------------------------------------------------------------------
1 | FILE=$1
2 |
3 | if [[ $FILE != "ae_photos" && $FILE != "apple2orange" && $FILE != "summer2winter_yosemite" && $FILE != "horse2zebra" && $FILE != "monet2photo" && $FILE != "cezanne2photo" && $FILE != "ukiyoe2photo" && $FILE != "vangogh2photo" && $FILE != "maps" && $FILE != "cityscapes" && $FILE != "facades" && $FILE != "iphone2dslr_flower" && $FILE != "ae_photos" ]]; then
4 | echo "Available datasets are: apple2orange, summer2winter_yosemite, horse2zebra, monet2photo, cezanne2photo, ukiyoe2photo, vangogh2photo, maps, cityscapes, facades, iphone2dslr_flower, ae_photos"
5 | exit 1
6 | fi
7 |
8 | URL=https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/$FILE.zip
9 | ZIP_FILE=./datasets/$FILE.zip
10 | TARGET_DIR=./datasets/$FILE/
11 | wget -N $URL -O $ZIP_FILE
12 | mkdir $TARGET_DIR
13 | unzip $ZIP_FILE -d ./datasets/
14 | rm $ZIP_FILE
15 |
--------------------------------------------------------------------------------
/data/download_cyclegan_datasetTrain.sh:
--------------------------------------------------------------------------------
1 | FILE=$1
2 |
3 | if [[ $FILE != "ae_photos" && $FILE != "apple2orange" && $FILE != "summer2winter_yosemite" && $FILE != "horse2zebra" && $FILE != "monet2photo" && $FILE != "cezanne2photo" && $FILE != "ukiyoe2photo" && $FILE != "vangogh2photo" && $FILE != "maps" && $FILE != "cityscapes" && $FILE != "facades" && $FILE != "iphone2dslr_flower" && $FILE != "ae_photos" ]]; then
4 | echo "Available datasets are: apple2orange, summer2winter_yosemite, horse2zebra, monet2photo, cezanne2photo, ukiyoe2photo, vangogh2photo, maps, cityscapes, facades, iphone2dslr_flower, ae_photos"
5 | exit 1
6 | fi
7 |
8 | URL=https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/$FILE.zip
9 | ZIP_FILE=./datasets/$FILE.zip
10 | TARGET_DIR=./datasets/$FILE/
11 | wget -N $URL -O $ZIP_FILE
12 | mkdir $TARGET_DIR
13 | unzip $ZIP_FILE -d ./datasets/
14 | rm $ZIP_FILE
15 |
--------------------------------------------------------------------------------
/data/download_pix2pix_dataset.sh:
--------------------------------------------------------------------------------
1 | FILE=$1
2 | URL=https://people.eecs.berkeley.edu/~tinghuiz/projects/pix2pix/datasets/$FILE.tar.gz
3 | TAR_FILE=./datasets/$FILE.tar.gz
4 | TARGET_DIR=./datasets/$FILE/
5 | wget -N $URL -O $TAR_FILE
6 | mkdir $TARGET_DIR
7 | tar -zxvf $TAR_FILE -C ./datasets/
8 | rm $TAR_FILE
--------------------------------------------------------------------------------
/data/lsun/README.md:
--------------------------------------------------------------------------------
1 | # LSUN
2 |
3 | Please check [LSUN webpage](http://www.yf.io/p/lsun) for more information about the dataset.
4 |
5 | ## Data Release
6 |
7 | All the images in one category are stored in one lmdb database
8 | file. The value
9 | of each entry is the jpg binary data. We resize all the images so
10 | that the
11 | smaller dimension is 256 and compress the images in jpeg with
12 | quality 75.
13 |
14 | ### Citing LSUN
15 |
16 | If you find LSUN dataset useful in your research, please consider citing:
17 |
18 | @article{yu15lsun,
19 | Author = {Yu, Fisher and Zhang, Yinda and Song, Shuran and Seff, Ari and Xiao, Jianxiong},
20 | Title = {LSUN: Construction of a Large-scale Image Dataset using Deep Learning with Humans in the Loop},
21 | Journal = {arXiv preprint arXiv:1506.03365},
22 | Year = {2015}
23 | }
24 |
25 | ### Download data
26 | Please make sure you have cURL installed
27 | ```bash
28 | # Download the whole latest data set
29 | python2.7 download.py
30 | # Download the whole latest data set to
31 | python2.7 download.py -o
32 | # Download data for bedroom
33 | python2.7 download.py -c bedroom
34 | # Download testing set
35 | python2.7 download.py -c test
36 | ```
37 |
38 | ## Demo code
39 |
40 | ### Dependency
41 |
42 | Install Python
43 |
44 | Install Python dependency: numpy, lmdb, opencv
45 |
46 | ### Usage:
47 |
48 | View the lmdb content
49 |
50 | ```bash
51 | python2.7 data.py view
52 | ```
53 |
54 | Export the images to a folder
55 |
56 | ```bash
57 | python2.7 data.py export --out_dir