|
| 1 | +""" |
| 2 | +Machine Learning models implemented with `PyTorch <https://pytorch.org/>`_. |
| 3 | +Models are saved under the directory in `model.pt`. |
| 4 | +
|
| 5 | +**General Usage:** |
| 6 | +
|
| 7 | +Training: |
| 8 | +
|
| 9 | +.. code-block:: console |
| 10 | +
|
| 11 | + $ dffml train \\ |
| 12 | + -model PYTORCH_MODEL_ENTRYPOINT \\ |
| 13 | + -model-features FEATURE_DEFINITION \\ |
| 14 | + -model-predict TO_PREDICT \\ |
| 15 | + -model-directory MODEL_DIRECTORY \\ |
| 16 | + -model-CONFIGS CONFIG_VALUES \\ |
| 17 | + -sources f=TRAINING_DATA_SOURCE_TYPE \\ |
| 18 | + -source-CONFIGS TRAINING_DATA \\ |
| 19 | + -log debug |
| 20 | +
|
| 21 | +Testing and Accuracy: |
| 22 | +
|
| 23 | +.. code-block:: console |
| 24 | +
|
| 25 | + $ dffml accuracy \\ |
| 26 | + -model PYTORCH_MODEL_ENTRYPOINT \\ |
| 27 | + -model-features FEATURE_DEFINITION \\ |
| 28 | + -model-predict TO_PREDICT \\ |
| 29 | + -model-directory MODEL_DIRECTORY \\ |
| 30 | + -model-CONFIGS CONFIG_VALUES \\ |
| 31 | + -sources f=TESTING_DATA_SOURCE_TYPE \\ |
| 32 | + -source-CONFIGS TESTING_DATA \\ |
| 33 | + -log debug |
| 34 | +
|
| 35 | +Predicting with trained model: |
| 36 | +
|
| 37 | +.. code-block:: console |
| 38 | +
|
| 39 | + $ dffml predict all \\ |
| 40 | + -model PYTORCH_MODEL_ENTRYPOINT \\ |
| 41 | + -model-features FEATURE_DEFINITION \\ |
| 42 | + -model-predict TO_PREDICT \\ |
| 43 | + -model-directory MODEL_DIRECTORY \\ |
| 44 | + -model-CONFIGS CONFIG_VALUES \\ |
| 45 | + -sources f=PREDICT_DATA_SOURCE_TYPE \\ |
| 46 | + -source-CONFIGS PREDICTION_DATA \\ |
| 47 | + -log debug |
| 48 | +
|
| 49 | +
|
| 50 | +**Pre-Trained Models Available:** |
| 51 | +
|
| 52 | ++----------------+---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 53 | +| Type | Model | Entrypoint | Architecture | |
| 54 | ++================+=================================+====================+================================================================================+ |
| 55 | +| Classification | AlexNet | alexnet | `AlexNet architecture <https://arxiv.org/abs/1404.5997>`_ | |
| 56 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 57 | +| | DenseNet-121 | densenet121 | `DenseNet architecture <https://arxiv.org/pdf/1608.06993.pdf>`_ | |
| 58 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 59 | +| | DenseNet-161 | densenet161 | | |
| 60 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 61 | +| | DenseNet-169 | densenet169 | | |
| 62 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 63 | +| | DenseNet-201 | densenet201 | | |
| 64 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 65 | +| | MnasNet 0.5 | mnasnet0_5 | `MnasNet architecture <https://arxiv.org/pdf/1807.11626.pdf>`_ | |
| 66 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 67 | +| | MnasNet 1.0 | mnasnet1_0 | | |
| 68 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 69 | +| | MobileNet V2 | mobilenet_v2 | `MobileNet V2 architecture <https://arxiv.org/abs/1801.04381>`_ | |
| 70 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 71 | +| | VGG-11 | vgg11 | `VGG-11 architecture Configuration "A" <https://arxiv.org/pdf/1409.1556.pdf>`_ | |
| 72 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 73 | +| | VGG-11 with batch normalization | vgg11_bn | | |
| 74 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 75 | +| | VGG-13 | vgg13 | `VGG-13 architecture Configuration "B" <https://arxiv.org/pdf/1409.1556.pdf>`_ | |
| 76 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 77 | +| | VGG-13 with batch normalization | vgg13_bn | | |
| 78 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 79 | +| | VGG-16 | vgg16 | `VGG-16 architecture Configuration "D" <https://arxiv.org/pdf/1409.1556.pdf>`_ | |
| 80 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 81 | +| | VGG-16 with batch normalization | vgg16_bn | | |
| 82 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 83 | +| | VGG-19 | vgg19 | `VGG-19 architecture Configuration "E" <https://arxiv.org/pdf/1409.1556.pdf>`_ | |
| 84 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 85 | +| | VGG-19 with batch normalization | vgg19_bn | | |
| 86 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 87 | +| | GoogleNet | googlenet | `GoogleNet architecture <http://arxiv.org/abs/1409.4842>`_ | |
| 88 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 89 | +| | Inception V3 | inception_v3 | `Inception V3 architecture <http://arxiv.org/abs/1512.00567>`_ | |
| 90 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 91 | +| | ResNet-18 | resnet18 | `ResNet architecture <https://arxiv.org/pdf/1512.03385.pdf>`_ | |
| 92 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 93 | +| | ResNet-34 | resnet34 | | |
| 94 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 95 | +| | ResNet-50 | resnet50 | | |
| 96 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 97 | +| | ResNet-101 | resnet101 | | |
| 98 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 99 | +| | ResNet-152 | resnet152 | | |
| 100 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 101 | +| | Wide ResNet-101-2 | wide_resnet101_2 | `Wide Resnet architecture <https://arxiv.org/pdf/1605.07146.pdf>`_ | |
| 102 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 103 | +| | Wide ResNet-50-2 | wide_resnet50_2 | | |
| 104 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 105 | +| | ShuffleNet V2 0.5 | shufflenet_v2_x0_5 | `Shuffle Net V2 architecture <https://arxiv.org/abs/1807.11164>`_ | |
| 106 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 107 | +| | ShuffleNet V2 1.0 | shufflenet_v2_x1_0 | | |
| 108 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 109 | +| | ResNext-101-32x8D | resnext101_32x8d | `ResNext architecture <https://arxiv.org/pdf/1611.05431.pdf>`_ | |
| 110 | +| +---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 111 | +| | ResNext-50-32x4D | resnext50_32x4d | | |
| 112 | ++----------------+---------------------------------+--------------------+--------------------------------------------------------------------------------+ |
| 113 | +
|
| 114 | +
|
| 115 | +**Usage Example:** |
| 116 | +
|
| 117 | +Example below uses ResNet-18 Model using the command line. |
| 118 | +
|
| 119 | +Let us take a simple example: **Classifying Ants and Bees Images** |
| 120 | +
|
| 121 | +First, we download the dataset and verify with ``sha384sum`` |
| 122 | +
|
| 123 | +.. code-block:: |
| 124 | +
|
| 125 | + curl -LO https://download.pytorch.org/tutorial/hymenoptera_data.zip |
| 126 | + sha384sum -c - << EOF |
| 127 | + 491db45cfcab02d99843fbdcf0574ecf99aa4f056d52c660a39248b5524f9e6e8f896d9faabd27ffcfc2eaca0cec6f39 /home/tron/Desktop/Development/hymenoptera_data.zip |
| 128 | + EOF |
| 129 | + hymenoptera_data.zip: OK |
| 130 | +
|
| 131 | +Unzip the file |
| 132 | +
|
| 133 | +.. code-block:: |
| 134 | +
|
| 135 | + unzip hymenoptera_data.zip |
| 136 | +
|
| 137 | +Train the model |
| 138 | +
|
| 139 | +.. literalinclude:: /../model/pytorch/examples/resnet18/train.sh |
| 140 | +
|
| 141 | +Assess accuracy |
| 142 | +
|
| 143 | +.. literalinclude:: /../model/pytorch/examples/resnet18/accuracy.sh |
| 144 | +
|
| 145 | +Output: |
| 146 | +
|
| 147 | +.. code-block:: |
| 148 | +
|
| 149 | + 0.9215686274509803 |
| 150 | +
|
| 151 | +Create a csv file with the names of the images to predict, whether they are ants or bees. |
| 152 | +
|
| 153 | +.. literalinclude:: /../model/pytorch/examples/resnet18/unknown_data.sh |
| 154 | +
|
| 155 | +Make the predictions |
| 156 | +
|
| 157 | +.. literalinclude:: /../model/pytorch/examples/resnet18/predict.sh |
| 158 | +
|
| 159 | +Output: |
| 160 | +
|
| 161 | +.. literalinclude:: /../model/pytorch/examples/resnet18/output.txt |
| 162 | +
|
| 163 | +""" |
0 commit comments