You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[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)
This documentation is about installing AWS tools and configuring AWS environment to download LADI dataset and load dataset in Python locally and remotely.
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.
7
24
8
25
In this project, we are focusing on ResNet and AlexNet
@@ -39,6 +56,7 @@ MobileNets are based on a streamlined architecture that uses depth-wise separabl
39
56
```python
40
57
model = make_model('mobilenet', num_classes=2, pretrained=True)
41
58
```
59
+
42
60
## Define Image Transforms
43
61
44
62
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.
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.
@@ -87,6 +106,7 @@ Users can change the `default` argument for `--model-name` to use various pretra
87
106
For a full list of all pretrained model, users can visit [PyTorch Image Classification Models](https://pytorch.org/docs/stable/torchvision/models.html).
88
107
89
108
## Train model
109
+
90
110
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.
print('Accuracy of the network on the 200 test images: %d%%'% (
147
169
100* correct / total))
148
170
```
171
+
149
172
## Run Training and Testing Step
150
173
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.
151
174
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):
176
199
train(model, epoch, optimizer, train_loader)
177
200
test(model, test_loader)
178
201
```
202
+
179
203
## Saving and loading models for parameter tuning
180
204
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.
182
206
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.
184
208
185
209
Parameter Tuning Example: (define new parameter using "parser.add_argument" function)
186
210
* Change the number of epochs from 30 to 50
187
211
* Change the batch size from 4 to 16
188
212
* Change the learing rate from 0.1 to 0.01
189
213
190
214
### ResNet / DenseNet / MobileNet
215
+
191
216
```python
192
217
model_name ='resnet50_2_58.pth'
193
218
PATH=f"/content/drive/My Drive/{model_name}"
@@ -214,7 +239,9 @@ for epoch in range(0, args.epochs):
214
239
train(model, epoch, optimizer, train_loader)
215
240
test(model, test_loader)
216
241
```
242
+
217
243
### AlexNet
244
+
218
245
```python
219
246
model = make_model(
220
247
model_name,
@@ -223,6 +250,7 @@ model = make_model(
223
250
input_size= (256,256),
224
251
)
225
252
```
253
+
226
254
## Load saved models to predict image labels
227
255
228
256
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.
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
285
311
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.
287
313
314
+
In terms of future improvement, we are looking into fine-tuning the MobilNetV2 and ResNet 101 models with more images.
0 commit comments