Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 8165dc9

Browse files
authored
Initial markdown clean-up (#1)
* Mlint formatting updates and added default README No technical content was changed or added * Rename files for easier handling Removed whitespace from tutorial makrdown filenames Create LICENSE file instead of linking to external license Added default READMEs for each directory Changed image links from hard coded to relative Removed whitespace from tutorial markdown filenames * Update Pytorch_Data_Load.md fixed relative link * Remove incomplete sagemaker tutorial
1 parent b6f2f8e commit 8165dc9

11 files changed

Lines changed: 189 additions & 286 deletions

Data/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Data
2+
3+
Default directory for sample data used by tutorials.
4+
5+
## Distribution Statement
6+
7+
[BSD -Clause License](https://github.com/LADI-Dataset/ladi-tutorial/blob/master/LICENSE)

Images/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Images
2+
3+
Default directory for images used for documentation.
4+
5+
## Distribution Statement
6+
7+
[BSD -Clause License](https://github.com/LADI-Dataset/ladi-tutorial/blob/master/LICENSE)

README.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,45 @@
11
# Tutorials Guide
2-
- [Getting Started](#getting-started)
3-
- [Getting Dataset](#getting-dataset)
4-
- [Clean and Validate LADI Dataset](#clean-and-validate-ladi-dataset)
5-
- [PyTorch Data Loading](#pytorch-data-loading)
6-
- [Train and Test A Classifier](#train-and-test-a-classifier)
7-
- [Fine Tuning Torchvision Models - ResNet and AlexNet](#fine-tuning-torchvision-models)
8-
- [SageMaker - Build, Train, and Deploy ML Models](#sagemaker-build-train-and-deploy-ml-models)
9-
10-
## Getting Started
11-
[Getting Started](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Getting%20Started.md)
122

13-
This documentation is about installing AWS tools and configuring AWS environment to download LADI dataset and load dataset in Python locally and remotely.
3+
Tutorial for the Low Altitude Disaster Imagery (LADI) dataset. This tutorial was originally forked from a [Penn State Learning Factory](https://www.lf.psu.edu/) capstone project
4+
5+
- [Tutorials Guide](#tutorials-guide)
6+
- [Getting Started](#getting-started)
7+
- [Clean and Validate LADI Dataset](#clean-and-validate-ladi-dataset)
8+
- [PyTorch Data Loading](#pytorch-data-loading)
9+
- [Train and Test A Classifier](#train-and-test-a-classifier)
10+
- [Fine Tuning Torchvision Models](#fine-tuning-torchvision-models)
11+
- [Distribution Statement](#distribution-statement)
12+
13+
## Getting Started
1414

15-
## Getting Dataset
16-
[Getting Dataset](https://github.com/NaeRong/DS440_Capstone/blob/master/Data)
15+
[Getting Started](./Tutorials/Get_Started.md)
1716

18-
This folder contains dataset with 2000 images and labels.
17+
This documentation is about installing AWS tools and configuring AWS environment to download LADI dataset and load dataset in Python locally and remotely.
1918

2019
## Clean and Validate LADI Dataset
21-
[Clean and Validate LADI Dataset](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Clean%20and%20Validate%20LADI%20Dataset.md)
20+
21+
[Clean and Validate LADI Dataset](./Tutorials/Clean_Validate.md)
2222

2323
This documentation is about clean the LADI dataset. For this project, we have only extracted 2000 images for training.
2424

2525
## PyTorch Data Loading
26-
[PyTorch Data Loading](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Pytorch%20Data%20Load.md)
26+
27+
[PyTorch Data Loading](./Tutorials/Pytorch_Data_Load.md)
2728

2829
This documentation is about loading LADI dataset in PyTorch framework including examples of writing custom `Dataset`, `Transforms` and `Dataloader`.
2930

3031
## Train and Test A Classifier
31-
[Train and Test A Classifier](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Train%20and%20Test%20A%20Classifier.md)
32+
33+
[Train and Test A Classifier](./Tutorials/Train_Test_Classifier.md)
3234

3335
This documentation is about training and testing a classifier model using Convolutional Neural Network (CNN) from scratch.
3436

3537
## Fine Tuning Torchvision Models
36-
[Fine Tuning Torchvision Models](Tutorials/Fine%20Tuning%20Torchvision%20Models.md)
38+
39+
[Fine Tuning Torchvision Models](./Tutorials/Fine_Tune_Torchvision_Models.md)
3740

3841
This documentation is about training and testing a classifier model using pre-trained ResNet and AlexNet.
3942

40-
## SageMaker Build Train and Deploy ML Models
41-
[SageMaker Build Train and Deploy ML Models](Tutorials/SageMaker%20-%20Build,%20Train,%20and%20Deploy%20ML%20Model.md)
43+
## Distribution Statement
4244

43-
This documentation is about migrating model scripts into the AWS SageMaker environment.
45+
[BSD -Clause License](https://github.com/LADI-Dataset/ladi-tutorial/blob/master/LICENSE)

Tutorials/Clean and Validate LADI Dataset.md renamed to Tutorials/Clean_Validate.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Clean and Validate LADI Dataset
2-
- [Clean and validate dataset](#clean_and_validate_ladi_dataset)
3-
* [Clean the aggregated Responses .tsv file](#clean_the_aggregated_responses_.tsv_file)
4-
* [Generate True/False label](#generate_true/false_label)
2+
3+
- [Clean and Validate LADI Dataset](#clean-and-validate-ladi-dataset)
4+
- [Clean the aggregated Responses .tsv file](#clean-the-aggregated-responses-tsv-file)
5+
- [Generate True/False label](#generate-truefalse-label)
6+
- [Distribution Statement](#distribution-statement)
57

68
## Clean the aggregated Responses .tsv file
79

@@ -132,3 +134,7 @@ label_df = pd.DataFrame(label_data, columns = ['s3_path', 'label'])
132134
flood_tiny_metadata.to_csv('/content/drive/My Drive/Colab Notebooks/DS440_data/flood_tiny_metadata.csv')
133135
label_df.to_csv('/content/drive/My Drive/Colab Notebooks/DS440_data/flood_tiny_label.csv')
134136
```
137+
138+
## Distribution Statement
139+
140+
[BSD -Clause License](https://github.com/LADI-Dataset/ladi-tutorial/blob/master/LICENSE)

Tutorials/Fine Tuning Torchvision Models.md renamed to Tutorials/Fine_Tune_Torchvision_Models.md

Lines changed: 73 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
# Fine Tuning Torchvision Models
1+
# Fine Tuning Torchvision Models
2+
3+
- [Fine Tuning Torchvision Models](#fine-tuning-torchvision-models)
4+
- [Initialize the pretrained model](#initialize-the-pretrained-model)
5+
- [Define Image Transforms](#define-image-transforms)
6+
- [Define model parameters](#define-model-parameters)
7+
- [Train model](#train-model)
8+
- [Test Model](#test-model)
9+
- [Run Training and Testing Step](#run-training-and-testing-step)
10+
- [Saving and loading models for parameter tuning](#saving-and-loading-models-for-parameter-tuning)
11+
- [ResNet / DenseNet / MobileNet](#resnet--densenet--mobilenet)
12+
- [AlexNet](#alexnet)
13+
- [Load saved models to predict image labels](#load-saved-models-to-predict-image-labels)
14+
- [Model Accuracy](#model-accuracy)
15+
- [Python Scripts](#python-scripts)
16+
- [Confusion Matrix for ResNet 101](#confusion-matrix-for-resnet-101)
17+
- [Python Script for Confusion Matrix](#python-script-for-confusion-matrix)
18+
- [Distribution Statement](#distribution-statement)
219

320
## Initialize the pretrained model
421

5-
Pytorch provides cnn_finetune, which includes multiple deep learning models, pre-trained on the ImageNet dataset. The package automatically replaces classifier on top of the network, which allows the user to train a network with a dataset that has a different number of classes.
6-
Also, cnn_finetune allows users to add a dropout layer or a custom pooling layer.
22+
Pytorch provides `cnn_finetune`, which includes multiple deep learning models, pre-trained on the ImageNet dataset. The package automatically replaces classifier on top of the network, which allows the user to train a network with a dataset that has a different number of classes.
23+
Also, `cnn_finetune` allows users to add a dropout layer or a custom pooling layer.
724

8-
In this project, we are focusing on ResNet and AlexNet
9-
* ResNet (resnet18, resnet34, resnet50, resnet101, resnet152)
10-
* AlexNet (alexnet)
11-
* DenseNet (densenet161)
12-
* MobileNet (mobilenet)
25+
In this project, we are focusing on ResNet and AlexNet:
26+
27+
- ResNet (resnet18, resnet34, resnet50, resnet101, resnet152)
28+
- AlexNet (alexnet)
29+
- DenseNet (densenet161)
30+
- MobileNet (mobilenet)
1331

1432
Example usage:
1533

@@ -39,6 +57,7 @@ MobileNets are based on a streamlined architecture that uses depth-wise separabl
3957
```python
4058
model = make_model('mobilenet', num_classes=2, pretrained=True)
4159
```
60+
4261
## Define Image Transforms
4362

4463
Having a large dataset is crucial for the performance of the deep learning model. However, we can improve the performance of the model by augmenting the data we already have.
@@ -50,14 +69,15 @@ transformed_dataset = FloodTinyDataset(csv_file=csv_file,
5069
label_csv = label_csv, transform=transforms.Compose([transforms.Resize(256),
5170
transforms.RandomRotation(10),
5271
transforms.RandomCrop(256),
53-
transforms.RandomHorizontalFlip(),
72+
transforms.RandomHorizontalFlip(),
5473
transforms.ToTensor()
5574
]))
5675
```
76+
5777
## Define model parameters
5878

5979
This section defines all the model parameters. Users can reference the parameter by calling args.{argument}.
60-
For this project, we have defined batch-size / number of epochs / learning rate / momentum / use of Cuda / model name. All the parameters are subject to change and add depends on the user preference.
80+
For this project, we have defined batch-size / number of epochs / learning rate / momentum / use of Cuda / model name. All the parameters are subject to change and add depends on the user preference.
6181

6282
```python
6383
parser = argparse.ArgumentParser(description='cnn_finetune')
@@ -75,7 +95,9 @@ parser.add_argument('--no-cuda', action='store_true', default=False,
7595
parser.add_argument('--model-name', type=str, default='resnet34', metavar='M',
7696
help='model name (default: resnet34)')
7797
```
98+
7899
Users can use "to.device" to switch the training from using cpu to gpu.
100+
79101
```python
80102
args = parser.parse_args()
81103
use_cuda = not args.no_cuda and torch.cuda.is_available()
@@ -87,6 +109,7 @@ Users can change the `default` argument for `--model-name` to use various pretra
87109
For a full list of all pretrained model, users can visit [PyTorch Image Classification Models](https://pytorch.org/docs/stable/torchvision/models.html).
88110

89111
## Train model
112+
90113
The train function handles the training and validation of a given model. As input, it takes a PyTorch model, a dictionary of dataloaders, a loss function, an optimizer, and a specified number of epochs to train and validate for. The train function also print loss values for every 20 mini-batches.
91114

92115
```python
@@ -121,7 +144,9 @@ def train(model, epoch, optimizer, train_loader, criterion=nn.CrossEntropyLoss()
121144

122145
print('Finished Training')
123146
```
147+
124148
## Test Model
149+
125150
```python
126151
def test(model, test_loader, criterion=nn.CrossEntropyLoss()):
127152
model.eval()
@@ -146,7 +171,9 @@ def test(model, test_loader, criterion=nn.CrossEntropyLoss()):
146171
print('Accuracy of the network on the 200 test images: %d %%' % (
147172
100 * correct / total))
148173
```
174+
149175
## Run Training and Testing Step
176+
150177
Finally, the last step is to setup the loss for the model, then run the training and testing function for the set number of epochs.
151178
In this step, we also create an optimizer that only updates the desired parameters. To construct an Optimizer you have to give it an iterable containing the parameters (all should be Variable s) to optimize. Then, you can specify optimizer-specific options such as the learning rate, weight decay, etc.
152179
The common optimizer includes:
@@ -176,18 +203,21 @@ for epoch in range(1, args.epochs):
176203
train(model, epoch, optimizer, train_loader)
177204
test(model, test_loader)
178205
```
206+
179207
## Saving and loading models for parameter tuning
180208

181-
In PyTorch, the user can save the trained model into a .pt or .pth file extension. In this case, we are saving the resnet50 model as "resnet50_2_58.pth". By referencing the path, PyTorch will load the model's parameter. Users can define a new set of model parameters before this step.
209+
In PyTorch, the user can save the trained model into a .pt or .pth file extension. In this case, we are saving the resnet50 model as "resnet50_2_58.pth". By referencing the path, PyTorch will load the model's parameter. Users can define a new set of model parameters before this step.
182210

183-
In this step, we used the existing model to predict the new dataset.
211+
In this step, we used the existing model to predict the new dataset.
184212

185213
Parameter Tuning Example: (define new parameter using "parser.add_argument" function)
186-
* Change the number of epochs from 30 to 50
187-
* Change the batch size from 4 to 16
188-
* Change the learing rate from 0.1 to 0.01
214+
215+
- Change the number of epochs from 30 to 50
216+
- Change the batch size from 4 to 16
217+
- Change the learing rate from 0.1 to 0.01
189218

190219
### ResNet / DenseNet / MobileNet
220+
191221
```python
192222
model_name = 'resnet50_2_58.pth'
193223
PATH = f"/content/drive/My Drive/{model_name}"
@@ -214,7 +244,9 @@ for epoch in range(0, args.epochs):
214244
train(model, epoch, optimizer, train_loader)
215245
test(model, test_loader)
216246
```
247+
217248
### AlexNet
249+
218250
```python
219251
model = make_model(
220252
model_name,
@@ -223,6 +255,7 @@ model = make_model(
223255
input_size= (256,256),
224256
)
225257
```
258+
226259
## Load saved models to predict image labels
227260

228261
In this step, we are using the existing model to predict the new dataset. As the result, we can observe the label prediction on 8 images.
@@ -276,82 +309,43 @@ _, predicted = torch.max(outputs, 1)
276309
print('Predicted: ', ' '.join('%5s' % predicted[j]
277310
for j in range(8)))
278311
```
279-
![img](https://github.com/NaeRong/DS440_Capstone/blob/master/Images/pred.png)
280-
281-
282-
## Model Accuracy
283312

284-
The accuracy and size for each model is shown in the table. Our ResNet 101 model can achieve the best accuracy of 79%. Our MobileNet V2 has a very small model size of 17 MB compared to other models, so it has the potential to be deployed on a hardware device.
313+
![pred.png](../Images/pred.png)
285314

286-
In terms of future improvement, we are looking into fine-tuning the MobilNetV2 and ResNet 101 models with more images.
315+
## Model Accuracy
287316

317+
The accuracy and size for each model is shown in the table. Our ResNet 101 model can achieve the best accuracy of 79%. Our MobileNet V2 has a very small model size of 17 MB compared to other models, so it has the potential to be deployed on a hardware device.
288318

319+
In terms of future improvement, we are looking into fine-tuning the MobilNetV2 and ResNet 101 models with more images.
289320

290-
| Model | Epoch | Accuracy | Model Size (MB)|
291-
|---------------|------ |------------ |----------------|
292-
| ResNet 34 | 30 | 72% | 163 |
321+
| Model | Epoch | Accuracy| Model Size (MB)|
322+
|---------------|------|------------|----------------|
323+
| ResNet 34 | 30 | 72% | 163 |
293324
| MobilenetV2 | 30 | 73% | 17 |
294-
| ResNet 50 | 30 | 75% | 180 |
295-
| AlexNet | 30 | 76% | 539 |
296-
| densenet 161 | 30 | 77% | 203 |
297-
| ResNet 101 | 30 | 79% | 325 |
325+
| ResNet 50 | 30 | 75% | 180 |
326+
| AlexNet | 30 | 76% | 539 |
327+
| densenet 161| 30 | 77% | 203 |
328+
| ResNet 101 | 30 | 79% | 325 |
298329

299-
### Python Scripts
300-
* AlexNet model
301-
[This link](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/alexnet.py)
330+
### Python Scripts
302331

303-
* ResNet 34 model
304-
[This link](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/resnset34.py)
332+
- [AlexNet model](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/alexnet.py)
333+
- [ResNet 34 model](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/resnset34.py)
334+
- [ResNet 101 model](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/resnset101.py)
335+
- [DenseNet 161 model](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/densenet.py)
336+
- [Mobilenet V2 model](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/mobilenetv2.py)
305337

306-
* ResNet 101 model
307-
[This link](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/resnset101.py)
338+
## Confusion Matrix for ResNet 101
308339

309-
* DenseNet 161 model
310-
[This link](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/densenet.py)
340+
The true positives rate and true negatives rate are both about 80%, which indicates a good precision / recall of our model.
311341

312-
* Mobilenet V2 model
313-
[This link](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/mobilenetv2.py)
342+
![confusionmatrix](../Images/cm.png)
314343

315-
## Confusion Matrix for ResNet 101
344+
### Python Script for Confusion Matrix
316345

317-
The true positives rate and true negatives rate are both about 80%, which indicates a good precision / recall of our model.
346+
- [Confusion Matrix](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/Confusion_Matrix.py)
347+
- [Confusion Matrix Plot](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/Plot_Confusion_Matrix.py)
318348

319-
![img](https://github.com/NaeRong/DS440_Capstone/blob/master/Images/cm.png)
349+
## Distribution Statement
320350

321-
### Python Script for Confusion Matrix
322-
* Confusion Matrix
323-
[This link](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/Confusion_Matrix.py)
324-
* Confusion Matrix Plot
325-
[This link](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/Plot_Confusion_Matrix.py)
326-
327-
## License
328-
329-
[BSD 3-Clause License](https://github.com/pytorch/tutorials/blob/master/LICENSE)
330-
331-
Copyright (c) 2017, Pytorch contributors
332-
All rights reserved.
333-
334-
Redistribution and use in source and binary forms, with or without
335-
modification, are permitted provided that the following conditions are met:
336-
337-
* Redistributions of source code must retain the above copyright notice, this
338-
list of conditions and the following disclaimer.
339-
340-
* Redistributions in binary form must reproduce the above copyright notice,
341-
this list of conditions and the following disclaimer in the documentation
342-
and/or other materials provided with the distribution.
343-
344-
* Neither the name of the copyright holder nor the names of its
345-
contributors may be used to endorse or promote products derived from
346-
this software without specific prior written permission.
347-
348-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
349-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
350-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
351-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
352-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
353-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
354-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
355-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
356-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
357-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
351+
[BSD -Clause License](https://github.com/LADI-Dataset/ladi-tutorial/blob/master/LICENSE)

0 commit comments

Comments
 (0)