From fbea931fba64c41b45f9030ad777455df72d7ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mentine=20Bonneau?= Date: Wed, 22 Dec 2021 20:45:07 +0100 Subject: [PATCH] =?UTF-8?q?Modifs=20archi=20donn=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Oiseau.ipynb | 139 ++++++++++-------- data/.DS_Store | Bin 6148 -> 6148 bytes .../preprocessing_example/.DS_Store | Bin .../preprocessing_example/bird_0_17.jpg | Bin .../preprocessing_example/bird_0_2061.jpg | Bin .../preprocessing_example/bird_0_5194.jpg | Bin .../preprocessing_example/bird_0_6313.jpg | Bin .../preprocessing_example/bird_0_6504.jpg | Bin .../preprocessing_example/bird_0_6971.jpg | Bin .../preprocessing_example/bird_0_7861.jpg | Bin .../preprocessing_example/bird_0_8433.jpg | Bin .../.DS_Store | Bin 6148 -> 6148 bytes data/validation/.DS_Store | Bin 0 -> 6148 bytes 13 files changed, 76 insertions(+), 63 deletions(-) rename data/{sample_160_Ntrain_40_Nval => }/preprocessing_example/.DS_Store (100%) rename data/{sample_160_Ntrain_40_Nval => }/preprocessing_example/bird_0_17.jpg (100%) rename data/{sample_160_Ntrain_40_Nval => }/preprocessing_example/bird_0_2061.jpg (100%) rename data/{sample_160_Ntrain_40_Nval => }/preprocessing_example/bird_0_5194.jpg (100%) rename data/{sample_160_Ntrain_40_Nval => }/preprocessing_example/bird_0_6313.jpg (100%) rename data/{sample_160_Ntrain_40_Nval => }/preprocessing_example/bird_0_6504.jpg (100%) rename data/{sample_160_Ntrain_40_Nval => }/preprocessing_example/bird_0_6971.jpg (100%) rename data/{sample_160_Ntrain_40_Nval => }/preprocessing_example/bird_0_7861.jpg (100%) rename data/{sample_160_Ntrain_40_Nval => }/preprocessing_example/bird_0_8433.jpg (100%) rename data/{sample_160_Ntrain_40_Nval => train}/.DS_Store (74%) create mode 100644 data/validation/.DS_Store diff --git a/Oiseau.ipynb b/Oiseau.ipynb index ff56c45..9d859e3 100644 --- a/Oiseau.ipynb +++ b/Oiseau.ipynb @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -81,9 +81,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[name: \"/device:CPU:0\"\n", + "device_type: \"CPU\"\n", + "memory_limit: 268435456\n", + "locality {\n", + "}\n", + "incarnation: 6212331521511793857\n", + "]\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "2021-12-22 20:34:12.391220: I tensorflow/core/platform/cpu_feature_guard.cc:145] This TensorFlow binary is optimized with Intel(R) MKL-DNN to use the following CPU instructions in performance critical operations: SSE4.1 SSE4.2\n", + "To enable them in non-MKL-DNN operations, rebuild TensorFlow with the appropriate compiler flags.\n" + ] + } + ], "source": [ "from tensorflow.python.client import device_lib\n", "print(device_lib.list_local_devices())" @@ -91,9 +113,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "CPU\n" + ] + } + ], "source": [ "MODE = \"GPU\" if \"GPU\" in [k.device_type for k in device_lib.list_local_devices()] else \"CPU\"\n", "print(MODE)" @@ -132,25 +162,24 @@ "\n", "```\n", "data_dir\n", - "└───sample/\n", - "│ └───train/\n", - "│ │ └───absence/\n", - "│ │ │ │ absence_t_0001.jpg\n", - "│ │ │ │ absence_t_0002.jpg\n", - "│ │ │ │ ...\n", - "│ │ └───presence/\n", - "│ │ │ │ presence_t_0001.jpg\n", - "│ │ │ │ presence_t_0002.jpg\n", - "│ │ │ │ ...\n", - "│ └───validation/\n", - "│ │ └───absence/\n", - "│ │ │ │ absence_v_0001.jpg\n", - "│ │ │ │ absence_v_0002.jpg\n", - "│ │ │ │ ...\n", - "│ │ └───presence/\n", - "│ │ │ │ presence_v_0001.jpg\n", - "│ │ │ │ presence_v_0002.jpg\n", - "│ │ │ │ ...\n", + "└───train/\n", + "│ └───absence/\n", + "│ │ │ absence_t_0001.jpg\n", + "│ │ │ absence_t_0002.jpg\n", + "│ │ │ ...\n", + "│ └───presence/\n", + "│ │ │ presence_t_0001.jpg\n", + "│ │ │ presence_t_0002.jpg\n", + "│ │ │ ...\n", + "└───validation/\n", + "│ └───absence/\n", + "│ │ │ absence_v_0001.jpg\n", + "│ │ │ absence_v_0002.jpg\n", + "│ │ │ ...\n", + "│ └───presence/\n", + "│ │ │ presence_v_0001.jpg\n", + "│ │ │ presence_v_0002.jpg\n", + "│ │ │ ...\n", "```" ] }, @@ -158,23 +187,19 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Parameter" + "### Reading the data" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "data_dir = 'data/' # data path\n", "\n", "# Sample directory path\n", - "# That way we can use this algorithm with an other sample if we have mire pictures in the future.\n", - "\n", - "N_train = 160\n", - "N_val = 40\n", - "data_dir_sub = data_dir+'sample_%d_Ntrain_%d_Nval' %(N_train, N_val)" + "# That way we can use this algorithm with an other sample if we have mire pictures in the future.\n" ] }, { @@ -188,23 +213,11 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'kpi' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m/var/folders/83/bqq_97cs083fpgkn46bd5k5r0000gn/T/ipykernel_61636/3158407634.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mimg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkpi\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mload_img\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdata_dir_sub\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m'/train/presence/presence_t_0001.jpg'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mimg\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'kpi' is not defined" - ] - } - ], + "outputs": [], "source": [ - "img = kpi.load_img(data_dir_sub+'/train/presence/presence_t_0001.jpg') \n", + "img = kpi.load_img(data_dir+'/train/presence/presence_t_0001.jpg') \n", "img" ] }, @@ -281,15 +294,15 @@ "metadata": {}, "outputs": [], "source": [ - "img = kpi.load_img(data_dir_sub+\"/train/presence/presence_t_0001.jpg\")\n", + "img = kpi.load_img(data_dir+\"/train/presence/presence_t_0001.jpg\")\n", "x = kpi.img_to_array(img) \n", "x_ = np.expand_dims(x, axis=0)\n", "\n", - "if not(os.path.isdir(data_dir_sub+\"/preprocessing_example\")):\n", - " os.mkdir(data_dir_sub+\"/preprocessing_example\")\n", + "if not(os.path.isdir(data_dir+\"/preprocessing_example\")):\n", + " os.mkdir(data_dir+\"/preprocessing_example\")\n", "\n", " i = 0\n", - " for batch in datagen.flow(x_, batch_size=1,save_to_dir=data_dir_sub+\"/preprocessing_example\", save_prefix='bird', save_format='jpg'):\n", + " for batch in datagen.flow(x_, batch_size=1,save_to_dir=data_dir+\"/preprocessing_example\", save_prefix='bird', save_format='jpg'):\n", " i += 1\n", " if i > 7:\n", " break " @@ -330,8 +343,8 @@ ], "source": [ "X_list=[]\n", - "for f in os.listdir(data_dir_sub+\"/preprocessing_example\"):\n", - " X_list.append(kpi.img_to_array(kpi.load_img(data_dir_sub+\"/preprocessing_example/\"+f)))\n", + "for f in os.listdir(data_dir+\"/preprocessing_example\"):\n", + " X_list.append(kpi.img_to_array(kpi.load_img(data_dir+\"/preprocessing_example/\"+f)))\n", "\n", "\n", "fig=plt.figure(figsize=(16,8))\n", @@ -411,8 +424,8 @@ } ], "source": [ - "x_0 = kpi.img_to_array(kpi.load_img(data_dir_sub+\"/train/presence/presence_t_0001.jpg\"))\n", - "x_1 = kpi.img_to_array(kpi.load_img(data_dir_sub+\"/train/presence/presence_t_0002.jpg\"))\n", + "x_0 = kpi.img_to_array(kpi.load_img(data_dir+\"/train/presence/presence_t_0001.jpg\"))\n", + "x_1 = kpi.img_to_array(kpi.load_img(data_dir+\"/train/presence/presence_t_0002.jpg\"))\n", "x_0.shape, x_1.shape" ] }, @@ -461,14 +474,14 @@ "# subfolers of 'data/train', and indefinitely generate\n", "# batches of augmented image data\n", "train_generator = train_datagen.flow_from_directory(\n", - " data_dir_sub+\"/train/\", # this is the target directory\n", + " data_dir+\"/train/\", # this is the target directory\n", " target_size=(img_width, img_height), \n", " batch_size=batch_size,\n", " class_mode='binary') # since we use binary_crossentropy loss, we need binary labels\n", "\n", "# this is a similar generator, for validation data\n", "validation_generator = valid_datagen.flow_from_directory(\n", - " data_dir_sub+\"/validation/\",\n", + " data_dir+\"/validation/\",\n", " target_size=(img_width, img_height),\n", " batch_size=batch_size,\n", " class_mode='binary')" @@ -840,7 +853,7 @@ "datagen = kpi.ImageDataGenerator(rescale=1. / 255)\n", "\n", "generator = datagen.flow_from_directory(\n", - " data_dir_sub+\"/train\",\n", + " data_dir+\"/train\",\n", " target_size=(img_width, img_height),\n", " batch_size=batch_size,\n", " class_mode=None, # this means our generator will only yield batches of data, no labels\n", @@ -849,7 +862,7 @@ "\n", "\n", "generator = datagen.flow_from_directory(\n", - " data_dir_sub+\"/validation\",\n", + " data_dir+\"/validation\",\n", " target_size=(img_width, img_height),\n", " batch_size=batch_size,\n", " class_mode=None,\n", @@ -1044,7 +1057,7 @@ } ], "source": [ - "model_VGG_fcm.save_weights(data_dir_sub+'/weights_model_VGG_fully_connected_model_%d_epochs_%d_batch_size.h5' %(epochs, batch_size))" + "model_VGG_fcm.save_weights(data_dir+'/weights_model_VGG_fully_connected_model_%d_epochs_%d_batch_size.h5' %(epochs, batch_size))" ] }, { @@ -1113,7 +1126,7 @@ "top_model.add(kl.Dropout(0.5))\n", "top_model.add(kl.Dense(1, activation='sigmoid'))\n", "\n", - "top_model.load_weights(data_dir_sub+'/weights_model_VGG_fully_connected_model_%d_epochs_%d_batch_size.h5' %(epochs, batch_size))\n" + "top_model.load_weights(data_dir+'/weights_model_VGG_fully_connected_model_%d_epochs_%d_batch_size.h5' %(epochs, batch_size))\n" ] }, { @@ -1247,13 +1260,13 @@ "test_datagen = kpi.ImageDataGenerator(rescale=1. / 255)\n", "\n", "train_generator = train_datagen.flow_from_directory(\n", - " data_dir_sub+\"/train/\",\n", + " data_dir+\"/train/\",\n", " target_size=(img_height, img_width),\n", " batch_size=batch_size,\n", " class_mode='binary')\n", "\n", "validation_generator = test_datagen.flow_from_directory(\n", - " data_dir_sub+\"/validation/\",\n", + " data_dir+\"/validation/\",\n", " target_size=(img_height, img_width),\n", " batch_size=batch_size,\n", " class_mode='binary')\n" @@ -1390,7 +1403,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.7.11" }, "toc": { "nav_menu": {}, diff --git a/data/.DS_Store b/data/.DS_Store index a270f5cbf8550a8f4ab6467e135ac8f1a21582b6..96f619df0df3fc063d4458cbdcc16dac065473b4 100644 GIT binary patch literal 6148 zcmeHK&5qMB5FYP#!3_d>0PP-q;nqV-(TY8+6iPX803ih}5ZUe~IlH07!r0cL7=eK(PpHSg4kW z=ojUTZ0MFth(wN&0f!?9Ajh8(!+>F6-5C&T_bQ~2;i?t-bp3{qzzBxe{v2G0u{VOi zo8_q&aSy#dd1(~pMW^$bY-~2R&Yh>!qSi(0nKR}yr*Ml&-gmPn;^~1~j6Gd{$a(am z?s^AdFdMe6+~!H)hDne~=g<$(9S&!jmJTcOd00mDF@ zflc+;66gP&U*G@hPUgulU>NwX7$A*-Gw9=#^x1l5a^kFISProW5q70Q>4Hih$Fd@h e;vFnfu#brfqOGx1h%G4QkAS4XD8s;CW#AiI#Meat literal 6148 zcmeHKOHRW;41H6&C}Ptk?B)nWLa+^0*s|#X3Z&>3(BoPnKSfHhlWbfD1ZzHmy*XHi64Kkb ze@x2}az(e!fHSbkz@9#irT$<1-2ZO|`I9r?4D1vGVOUIy2~)D#+DlGqZKPgNMPyy8 lxDMeUm13@yQhZ2FLVuJ2F*j@#>7n?KK%&8oGw`Pjd;vl&M{588 diff --git a/data/sample_160_Ntrain_40_Nval/preprocessing_example/.DS_Store b/data/preprocessing_example/.DS_Store similarity index 100% rename from data/sample_160_Ntrain_40_Nval/preprocessing_example/.DS_Store rename to data/preprocessing_example/.DS_Store diff --git a/data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_17.jpg b/data/preprocessing_example/bird_0_17.jpg similarity index 100% rename from data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_17.jpg rename to data/preprocessing_example/bird_0_17.jpg diff --git a/data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_2061.jpg b/data/preprocessing_example/bird_0_2061.jpg similarity index 100% rename from data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_2061.jpg rename to data/preprocessing_example/bird_0_2061.jpg diff --git a/data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_5194.jpg b/data/preprocessing_example/bird_0_5194.jpg similarity index 100% rename from data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_5194.jpg rename to data/preprocessing_example/bird_0_5194.jpg diff --git a/data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_6313.jpg b/data/preprocessing_example/bird_0_6313.jpg similarity index 100% rename from data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_6313.jpg rename to data/preprocessing_example/bird_0_6313.jpg diff --git a/data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_6504.jpg b/data/preprocessing_example/bird_0_6504.jpg similarity index 100% rename from data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_6504.jpg rename to data/preprocessing_example/bird_0_6504.jpg diff --git a/data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_6971.jpg b/data/preprocessing_example/bird_0_6971.jpg similarity index 100% rename from data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_6971.jpg rename to data/preprocessing_example/bird_0_6971.jpg diff --git a/data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_7861.jpg b/data/preprocessing_example/bird_0_7861.jpg similarity index 100% rename from data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_7861.jpg rename to data/preprocessing_example/bird_0_7861.jpg diff --git a/data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_8433.jpg b/data/preprocessing_example/bird_0_8433.jpg similarity index 100% rename from data/sample_160_Ntrain_40_Nval/preprocessing_example/bird_0_8433.jpg rename to data/preprocessing_example/bird_0_8433.jpg diff --git a/data/sample_160_Ntrain_40_Nval/.DS_Store b/data/train/.DS_Store similarity index 74% rename from data/sample_160_Ntrain_40_Nval/.DS_Store rename to data/train/.DS_Store index 97b1dc1204962c79f741eb74026f25c474e2b65d..11c3d8331b3815de821699874d8409cab90fe429 100644 GIT binary patch literal 6148 zcmeHKu};H447E!of>=5--VZSJ4?-2bpg#afD;OFQf!J^6k63}3pWq*uc|KbuA)#VI zP}!32U3~VP^Ag1|5%J=FH7A-8Q3e&99AOv{Sr;A1#4NJNX^$JKXuY|bFRNzY?S{X| zfIPcHx}=isXic5xSGS#Xzj)M5QIwmegh%%FTD@eC&u7DZ>Spx=ul8ErmfmR@wRDSY zc4aj1>E`tCe)?oNjre_LwaafLuMQzTbq1UPXW(BmfSN6m9V`0i3^)VMz?K2|J_M*> zZWtBQrvpQ30f1AOlVC2rgv12H+%PI)1;QE%)KIn-gEbuXV1Bt_RMc={Yd+XcX6sNm zosRuOawpCeeRKw#fj$EVdO4H&fBt>{-w*ODXTTZQD+YL4EQVxM!3SsHR~h&K=LJy4 literal 6148 zcmeHK!EVz)5S?v9*`z|`04m45aLXZSP(=?&CWHeA5Ry?j07~uJN-Q~E%XSD5g8Uiq z3H$-~Uit_817E?+?i8pBhX}Q5tDR`(jdyouz0ca+3;>A1Eb0NY0YIV>Hd<)@BGgZM zO4hh#15ub91!y>c7)ty(aSS*HE;<9WcW*-u1@2n1zxQtf8H{0s?e8FfDfXrihx0NI zQypT|QJAMmS#`VL#oBt~+QxM$Te5Yd^~Rs*xnBjygf?Aj#sw1Se69Ltej3vPjPddX`0{$>ZA&DVwr6YHuwT{oQ^??c85>)M9tL z+fn!WJIiHLZr$xYc(Olz|6%cQ`RTL$1OiVeBR3h3;R`w|Fp!RW{(+w6Cj9A-ud78* z^>E1i(UBVNeLH-(YKG`PGvt#$R`5*W^sB7@tzTrR&c+yZ%qV4Wa`_nG?bVf zb__TM&X@r@9~3H~$5>l5M+X{H0w6Z9*$DbnOHhnr^cZW4*n=W$D54D&Tw(|tj_r!a zd5pD18xDet55Y4Fu26)T9rG(Q9E4}lS;v55;3Na<_OVU(|Koqx|0jdolViX!aHSX! zjiEmr;F9=mJ+(NxYZdA~DhZ9NEt(KCd>tEyuHrkWMzBwjgXl5V7O@4z{Sh!UIO7;N HR|b9pQTdc< diff --git a/data/validation/.DS_Store b/data/validation/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..11c3d8331b3815de821699874d8409cab90fe429 GIT binary patch literal 6148 zcmeHKu};H447E!of>=5--VZSJ4?-2bpg#afD;OFQf!J^6k63}3pWq*uc|KbuA)#VI zP}!32U3~VP^Ag1|5%J=FH7A-8Q3e&99AOv{Sr;A1#4NJNX^$JKXuY|bFRNzY?S{X| zfIPcHx}=isXic5xSGS#Xzj)M5QIwmegh%%FTD@eC&u7DZ>Spx=ul8ErmfmR@wRDSY zc4aj1>E`tCe)?oNjre_LwaafLuMQzTbq1UPXW(BmfSN6m9V`0i3^)VMz?K2|J_M*> zZWtBQrvpQ30f1AOlVC2rgv12H+%PI)1;QE%)KIn-gEbuXV1Bt_RMc={Yd+XcX6sNm zosRuOawpCeeRKw#fj$EVdO4H&fBt>{-w*ODXTTZQD+YL4EQVxM!3SsHR~h&K=LJy4 literal 0 HcmV?d00001