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

Commit 4ea5297

Browse files
committed
Mlint formatting updates and added defulat README
No technical content was changed or added
1 parent db4d0d5 commit 4ea5297

12 files changed

Lines changed: 235 additions & 256 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)

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2017, Pytorch contributors
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
* Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,59 @@
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-
2+
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+
- [Getting Dataset](#getting-dataset)
8+
- [Clean and Validate LADI Dataset](#clean-and-validate-ladi-dataset)
9+
- [PyTorch Data Loading](#pytorch-data-loading)
10+
- [Train and Test A Classifier](#train-and-test-a-classifier)
11+
- [Fine Tuning Torchvision Models](#fine-tuning-torchvision-models)
12+
- [SageMaker Build Train and Deploy ML Models](#sagemaker-build-train-and-deploy-ml-models)
13+
- [Distribution Statement](#distribution-statement)
14+
1015
## Getting Started
11-
[Getting Started](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Getting%20Started.md)
16+
17+
[Getting Started](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Getting%20Started.md)
1218

1319
This documentation is about installing AWS tools and configuring AWS environment to download LADI dataset and load dataset in Python locally and remotely.
1420

15-
## Getting Dataset
16-
[Getting Dataset](https://github.com/NaeRong/DS440_Capstone/blob/master/Data)
21+
## Getting Dataset
22+
23+
[Getting Dataset](https://github.com/NaeRong/DS440_Capstone/blob/master/Data)
1724

1825
This folder contains dataset with 2000 images and labels.
1926

2027
## Clean and Validate LADI Dataset
28+
2129
[Clean and Validate LADI Dataset](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Clean%20and%20Validate%20LADI%20Dataset.md)
2230

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

2533
## PyTorch Data Loading
26-
[PyTorch Data Loading](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Pytorch%20Data%20Load.md)
34+
35+
[PyTorch Data Loading](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Pytorch%20Data%20Load.md)
2736

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

3039
## Train and Test A Classifier
40+
3141
[Train and Test A Classifier](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Train%20and%20Test%20A%20Classifier.md)
3242

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

3545
## Fine Tuning Torchvision Models
46+
3647
[Fine Tuning Torchvision Models](Tutorials/Fine%20Tuning%20Torchvision%20Models.md)
3748

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

4051
## SageMaker Build Train and Deploy ML Models
52+
4153
[SageMaker Build Train and Deploy ML Models](Tutorials/SageMaker%20-%20Build,%20Train,%20and%20Deploy%20ML%20Model.md)
4254

43-
This documentation is about migrating model scripts into the AWS SageMaker environment.
55+
This documentation is about migrating model scripts into the AWS SageMaker environment.
56+
57+
## Distribution Statement
58+
59+
[BSD -Clause License](https://github.com/LADI-Dataset/ladi-tutorial/blob/master/LICENSE)

Tutorials/Clean and Validate LADI Dataset.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

Lines changed: 64 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
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

825
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)
26+
- ResNet (resnet18, resnet34, resnet50, resnet101, resnet152)
27+
- AlexNet (alexnet)
28+
- DenseNet (densenet161)
29+
- MobileNet (mobilenet)
1330

1431
Example usage:
1532

@@ -39,6 +56,7 @@ MobileNets are based on a streamlined architecture that uses depth-wise separabl
3956
```python
4057
model = make_model('mobilenet', num_classes=2, pretrained=True)
4158
```
59+
4260
## Define Image Transforms
4361

4462
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 +68,15 @@ transformed_dataset = FloodTinyDataset(csv_file=csv_file,
5068
label_csv = label_csv, transform=transforms.Compose([transforms.Resize(256),
5169
transforms.RandomRotation(10),
5270
transforms.RandomCrop(256),
53-
transforms.RandomHorizontalFlip(),
71+
transforms.RandomHorizontalFlip(),
5472
transforms.ToTensor()
5573
]))
5674
```
75+
5776
## Define model parameters
5877

5978
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.
79+
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.
6180

6281
```python
6382
parser = argparse.ArgumentParser(description='cnn_finetune')
@@ -87,6 +106,7 @@ Users can change the `default` argument for `--model-name` to use various pretra
87106
For a full list of all pretrained model, users can visit [PyTorch Image Classification Models](https://pytorch.org/docs/stable/torchvision/models.html).
88107

89108
## Train model
109+
90110
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.
91111

92112
```python
@@ -121,7 +141,9 @@ def train(model, epoch, optimizer, train_loader, criterion=nn.CrossEntropyLoss()
121141

122142
print('Finished Training')
123143
```
144+
124145
## Test Model
146+
125147
```python
126148
def test(model, test_loader, criterion=nn.CrossEntropyLoss()):
127149
model.eval()
@@ -146,6 +168,7 @@ def test(model, test_loader, criterion=nn.CrossEntropyLoss()):
146168
print('Accuracy of the network on the 200 test images: %d %%' % (
147169
100 * correct / total))
148170
```
171+
149172
## Run Training and Testing Step
150173
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.
151174
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.
@@ -176,18 +199,20 @@ for epoch in range(1, args.epochs):
176199
train(model, epoch, optimizer, train_loader)
177200
test(model, test_loader)
178201
```
202+
179203
## Saving and loading models for parameter tuning
180204

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.
205+
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.
182206

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

185209
Parameter Tuning Example: (define new parameter using "parser.add_argument" function)
186210
* Change the number of epochs from 30 to 50
187211
* Change the batch size from 4 to 16
188212
* Change the learing rate from 0.1 to 0.01
189213

190214
### ResNet / DenseNet / MobileNet
215+
191216
```python
192217
model_name = 'resnet50_2_58.pth'
193218
PATH = f"/content/drive/My Drive/{model_name}"
@@ -214,7 +239,9 @@ for epoch in range(0, args.epochs):
214239
train(model, epoch, optimizer, train_loader)
215240
test(model, test_loader)
216241
```
242+
217243
### AlexNet
244+
218245
```python
219246
model = make_model(
220247
model_name,
@@ -223,6 +250,7 @@ model = make_model(
223250
input_size= (256,256),
224251
)
225252
```
253+
226254
## Load saved models to predict image labels
227255

228256
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 +304,43 @@ _, predicted = torch.max(outputs, 1)
276304
print('Predicted: ', ' '.join('%5s' % predicted[j]
277305
for j in range(8)))
278306
```
279-
![img](https://github.com/NaeRong/DS440_Capstone/blob/master/Images/pred.png)
280-
281307

282-
## Model Accuracy
308+
![pred.png](./Images/pred.png)
283309

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.
310+
## Model Accuracy
285311

286-
In terms of future improvement, we are looking into fine-tuning the MobilNetV2 and ResNet 101 models with more images.
312+
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.
287313

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

289-
290-
| Model | Epoch | Accuracy | Model Size (MB)|
291-
|---------------|------ |------------ |----------------|
292-
| ResNet 34 | 30 | 72% | 163 |
316+
| Model | Epoch | Accuracy| Model Size (MB)|
317+
|---------------|------|------------|----------------|
318+
| ResNet 34 | 30 | 72% | 163 |
293319
| 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 |
320+
| ResNet 50 | 30 | 75% | 180 |
321+
| AlexNet | 30 | 76% | 539 |
322+
| densenet 161| 30 | 77% | 203 |
323+
| ResNet 101 | 30 | 79% | 325 |
298324

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

303-
* ResNet 34 model
304-
[This link](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/resnset34.py)
327+
- [AlexNet model](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/alexnet.py)
328+
- [ResNet 34 model](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/resnset34.py)
329+
- [ResNet 101 model](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/resnset101.py)
330+
- [DenseNet 161 model](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/densenet.py)
331+
- [Mobilenet V2 model](https://github.com/NaeRong/DS440_Capstone/blob/master/Tutorials/Model%20Script/mobilenetv2.py)
305332

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

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

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

315-
## Confusion Matrix for ResNet 101
339+
### Python Script for Confusion Matrix
316340

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

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

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.
346+
[BSD -Clause License](https://github.com/LADI-Dataset/ladi-tutorial/blob/master/LICENSE)

0 commit comments

Comments
 (0)