From 985bd10b344a8b99f7baf033fac53292662cc6ba Mon Sep 17 00:00:00 2001 From: oscarchaufour <101994223+oscarchaufour@users.noreply.github.com> Date: Thu, 30 Nov 2023 15:56:22 +0100 Subject: [PATCH] Update TD2 Deep Learning.ipynb --- TD2 Deep Learning.ipynb | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/TD2 Deep Learning.ipynb b/TD2 Deep Learning.ipynb index c6538b6..214d157 100644 --- a/TD2 Deep Learning.ipynb +++ b/TD2 Deep Learning.ipynb @@ -464,7 +464,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "In the ideal scenario, training and validation loss shoudl both decrease with the number of epoch. When overtfit occures, the validation loss starts to increase.\n", + "In the ideal scenario, training and validation loss should both decrease with the number of epoch. When overtfit occures, the validation loss starts to increase.\n", "Here, when number of epoch is higher than 12, validation loss increase and thus there is an overtfit." ] }, @@ -645,6 +645,7 @@ "class Net(nn.Module):\n", " def __init__(self):\n", " super(Net, self).__init__()\n", + " # the three convolutional layers\n", " self.conv1 = nn.Conv2d(3, 16, kernel_size = 3, padding = 1)\n", " self.conv2 = nn.Conv2d(16, 32, kernel_size = 3, padding = 1)\n", " self.conv3 = nn.Conv2d(32, 64, kernel_size = 3, padding = 1)\n", @@ -652,6 +653,7 @@ " self.relu = nn.ReLU()\n", " self.pool = nn.MaxPool2d(kernel_size = 2)\n", " \n", + " # the three fully connected layers\n", " self.fc1 = nn.Linear(64 * 4 * 4, 512)\n", " self.fc2 = nn.Linear(512, 64)\n", " self.fc3 = nn.Linear(64, 10) # 10 is the number of image classes, the output of the final layer \n", @@ -1539,6 +1541,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "The Resnet model can classify type of object/animal, but the results are not very precise, because it can only classify the types that he already know. \n", + "\n", "The Resnet model is accurate for classifying image containing only one object/animal. To test this model on classifying differents targets on a single image, we load images containing a cat and a dog, or a women and a horse. The two first predicted classes are returned.\n", "The image example \"chien_chat\" shows that when two targets are on the image, the model fails and detect here a Kuvasz and a Pyrenean Mountain Dog, therefore the dog is recognized, but the cat is not." ] @@ -1614,6 +1618,13 @@ "print_size_of_model(quantized_modelResnet, \"int8\")" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The quantized model almost has the same size as the non quantized model." + ] + }, { "cell_type": "code", "execution_count": null, @@ -2379,8 +2390,8 @@ "}\n", "\n", "data_dir = \"data/hymenoptera_data\"\n", - "# Create train, validation and test datasets and loaders\n", "\n", + "# Create train, validation and test datasets and loaders\n", "train_dataset = datasets.ImageFolder(os.path.join(data_dir, \"train\"), data_transforms[\"train\"])\n", "val_dataset = datasets.ImageFolder(os.path.join(data_dir, \"val\"), data_transforms[\"val\"])\n", "\n", @@ -2708,14 +2719,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The test score is the same as the test score of the previous model, but there are less neurones in this model, therefore it is considered better." + "The test score is the same as the test score of the previous model, but there are less neurones in this model, therefore this model version is considered better." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Apply the quantization (post and quantization aware) and evaluate impact on model size and accuracy." + "Apply the quantization (post training) and evaluate impact on model size and accuracy." ] }, { @@ -2818,6 +2829,24 @@ "The accuracy of the quantized model is the same as the accuracy of the non quantized model." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Conclusion" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This notebook study different model architectures (Resnet50, Convolutional Neural Network...), and different treatements that can be applied to the model, post and during training (quantization aware and post, dropout...). The different sizes accuracies, losses of the models have been computed and compared.\n", + "\n", + "The quantization appears to reduce the size of the models, in some case (CNN for example) the size can be divided by 3.\n", + "\n", + "The pre-trained models recognize types of animal or object, but the pre-trained models with fully connected layers trained for a specific classification are more performant." + ] + }, { "cell_type": "markdown", "id": "04a263f0", -- GitLab