{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-05-05T16:44:44.842306Z","iopub.execute_input":"2022-05-05T16:44:44.842606Z","iopub.status.idle":"2022-05-05T16:44:44.874572Z","shell.execute_reply.started":"2022-05-05T16:44:44.842530Z","shell.execute_reply":"2022-05-05T16:44:44.873804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('../input/cifar-10/trainLabels.csv')","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:44:44.876230Z","iopub.execute_input":"2022-05-05T16:44:44.876477Z","iopub.status.idle":"2022-05-05T16:44:44.907486Z","shell.execute_reply.started":"2022-05-05T16:44:44.876444Z","shell.execute_reply":"2022-05-05T16:44:44.906811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:44:44.908602Z","iopub.execute_input":"2022-05-05T16:44:44.909089Z","iopub.status.idle":"2022-05-05T16:44:44.927424Z","shell.execute_reply.started":"2022-05-05T16:44:44.909034Z","shell.execute_reply":"2022-05-05T16:44:44.926716Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install py7zr","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:44:44.929568Z","iopub.execute_input":"2022-05-05T16:44:44.929933Z","iopub.status.idle":"2022-05-05T16:45:13.284779Z","shell.execute_reply.started":"2022-05-05T16:44:44.929897Z","shell.execute_reply":"2022-05-05T16:45:13.283959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import py7zr\n\narchive = py7zr.SevenZipFile('../input/cifar-10/train.7z', mode='r')\narchive.extractall(path='../temp')","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:45:13.287767Z","iopub.execute_input":"2022-05-05T16:45:13.288021Z","iopub.status.idle":"2022-05-05T16:46:02.236076Z","shell.execute_reply.started":"2022-05-05T16:45:13.287986Z","shell.execute_reply":"2022-05-05T16:46:02.235217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd ../temp","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:02.237300Z","iopub.execute_input":"2022-05-05T16:46:02.239463Z","iopub.status.idle":"2022-05-05T16:46:02.300989Z","shell.execute_reply.started":"2022-05-05T16:46:02.239421Z","shell.execute_reply":"2022-05-05T16:46:02.300215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%ls","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:02.302348Z","iopub.execute_input":"2022-05-05T16:46:02.303552Z","iopub.status.idle":"2022-05-05T16:46:03.014239Z","shell.execute_reply.started":"2022-05-05T16:46:02.303510Z","shell.execute_reply":"2022-05-05T16:46:03.013393Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cd train","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:03.016105Z","iopub.execute_input":"2022-05-05T16:46:03.016404Z","iopub.status.idle":"2022-05-05T16:46:03.021759Z","shell.execute_reply.started":"2022-05-05T16:46:03.016367Z","shell.execute_reply":"2022-05-05T16:46:03.021016Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%pwd","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:03.023320Z","iopub.execute_input":"2022-05-05T16:46:03.023933Z","iopub.status.idle":"2022-05-05T16:46:03.032822Z","shell.execute_reply.started":"2022-05-05T16:46:03.023896Z","shell.execute_reply":"2022-05-05T16:46:03.031996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport matplotlib.image as img","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:03.034001Z","iopub.execute_input":"2022-05-05T16:46:03.034838Z","iopub.status.idle":"2022-05-05T16:46:03.038834Z","shell.execute_reply.started":"2022-05-05T16:46:03.034800Z","shell.execute_reply":"2022-05-05T16:46:03.038078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"im = img.imread('1.png')\n  \n# show image\nplt.imshow(im)","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:03.040068Z","iopub.execute_input":"2022-05-05T16:46:03.041027Z","iopub.status.idle":"2022-05-05T16:46:03.264487Z","shell.execute_reply.started":"2022-05-05T16:46:03.040990Z","shell.execute_reply":"2022-05-05T16:46:03.263728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes = df['label'].unique()","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:03.265597Z","iopub.execute_input":"2022-05-05T16:46:03.265854Z","iopub.status.idle":"2022-05-05T16:46:03.277783Z","shell.execute_reply.started":"2022-05-05T16:46:03.265820Z","shell.execute_reply":"2022-05-05T16:46:03.276844Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images_path = '/kaggle/temp/train'\nval_images_path = '/kaggle/temp/validation'\n# test_images_path = '/kaggle/temp/test'","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:03.279073Z","iopub.execute_input":"2022-05-05T16:46:03.279767Z","iopub.status.idle":"2022-05-05T16:46:03.286535Z","shell.execute_reply.started":"2022-05-05T16:46:03.279732Z","shell.execute_reply":"2022-05-05T16:46:03.285828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.mkdir(val_images_path)\nfor c in classes:\n    train_path=os.path.join(train_images_path,c)\n    if not os.path.exists(train_path):\n        os.mkdir(train_path)\n    validation_path=os.path.join(val_images_path,c)\n    if not os.path.exists(validation_path):\n        os.mkdir(validation_path)\n\n\nfor ind in df.index:\n    x=str(df['id'][ind])+\".png\"\n    path1=os.path.join(train_images_path,x)  #currently stored\n    \n    path2=os.path.join(train_images_path,df['label'][ind],x)\n    path3=os.path.join(val_images_path,df['label'][ind],x)\n    \n    r=np.random.random()\n    if r<=0.8:\n        os.replace(path1,path2)\n    else:\n        os.replace(path1,path3)\n","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:03.291059Z","iopub.execute_input":"2022-05-05T16:46:03.291487Z","iopub.status.idle":"2022-05-05T16:46:06.896900Z","shell.execute_reply.started":"2022-05-05T16:46:03.291458Z","shell.execute_reply":"2022-05-05T16:46:06.895923Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cd frog","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:06.898356Z","iopub.execute_input":"2022-05-05T16:46:06.898726Z","iopub.status.idle":"2022-05-05T16:46:06.912036Z","shell.execute_reply.started":"2022-05-05T16:46:06.898689Z","shell.execute_reply":"2022-05-05T16:46:06.911360Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"im.shape","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:06.932142Z","iopub.execute_input":"2022-05-05T16:46:06.932419Z","iopub.status.idle":"2022-05-05T16:46:07.320804Z","shell.execute_reply.started":"2022-05-05T16:46:06.932382Z","shell.execute_reply":"2022-05-05T16:46:07.319984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd ..","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:07.322089Z","iopub.execute_input":"2022-05-05T16:46:07.322450Z","iopub.status.idle":"2022-05-05T16:46:07.337140Z","shell.execute_reply.started":"2022-05-05T16:46:07.322412Z","shell.execute_reply":"2022-05-05T16:46:07.335983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd ..","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:07.338400Z","iopub.execute_input":"2022-05-05T16:46:07.338865Z","iopub.status.idle":"2022-05-05T16:46:07.352751Z","shell.execute_reply.started":"2022-05-05T16:46:07.338813Z","shell.execute_reply":"2022-05-05T16:46:07.351813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.preprocessing.image import ImageDataGenerator\ntrain_datagen = ImageDataGenerator(featurewise_center=False,\n                                  samplewise_center=False,\n                                  featurewise_std_normalization=False,\n                                  samplewise_std_normalization=False,\n                                  zca_whitening=False,\n#                                   rotation_range=10,\n#                                   zoom_range=0.1,\n#                                   width_shift_range=0.1,\n#                                   height_shift_range=0.1,\n                                  horizontal_flip=False,\n                                  vertical_flip=False\n                                  )\n\ntrain_generator = train_datagen.flow_from_directory(\n    directory=r\"./train/\",\n    target_size=(32, 32),\n    color_mode=\"rgb\",\n    batch_size=32,\n    class_mode=\"categorical\",\n    shuffle=True,\n    seed=42\n)\n\nval_datagen = ImageDataGenerator(featurewise_center=False,\n                                  samplewise_center=False,\n                                  featurewise_std_normalization=False,\n                                  samplewise_std_normalization=False,\n                                  zca_whitening=False,\n#                                   rotation_range=10,\n#                                   zoom_range=0.1,\n#                                   width_shift_range=0.1,\n#                                   height_shift_range=0.1,\n                                  horizontal_flip=False,\n                                  vertical_flip=False\n                                  )\n\nval_generator = val_datagen.flow_from_directory(\n    directory=r\"./validation/\",\n    target_size=(32, 32),\n    color_mode=\"rgb\",\n    batch_size=32,\n    class_mode=\"categorical\",\n    shuffle=True,\n    seed=42\n)","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:07.354330Z","iopub.execute_input":"2022-05-05T16:46:07.354797Z","iopub.status.idle":"2022-05-05T16:46:15.839312Z","shell.execute_reply.started":"2022-05-05T16:46:07.354759Z","shell.execute_reply":"2022-05-05T16:46:15.838533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train_generator.class_indices)","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:15.840465Z","iopub.execute_input":"2022-05-05T16:46:15.841037Z","iopub.status.idle":"2022-05-05T16:46:15.851233Z","shell.execute_reply.started":"2022-05-05T16:46:15.840994Z","shell.execute_reply":"2022-05-05T16:46:15.850562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras import Sequential\nfrom keras.utils.np_utils import to_categorical\nfrom tensorflow.keras.layers import Conv2D, MaxPool2D , Dense,Activation, Flatten,Dropout,BatchNormalization\n# from keras.preprocessing.image import ImageDataGenerator","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:15.852563Z","iopub.execute_input":"2022-05-05T16:46:15.852895Z","iopub.status.idle":"2022-05-05T16:46:15.862227Z","shell.execute_reply.started":"2022-05-05T16:46:15.852859Z","shell.execute_reply":"2022-05-05T16:46:15.861475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow import keras\nfrom keras.callbacks import ReduceLROnPlateau\n\nreduceLROnPlateau = ReduceLROnPlateau(monitor='val_accuracy',\n                                     patience=3,\n                                     verbose=1,\n                                     factor=0.1,\n                                     min_lr=0.00001)\nearly_stopping_callback = keras.callbacks.EarlyStopping(monitor='val_accuracy', patience=20, restore_best_weights=True)\n","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:15.864997Z","iopub.execute_input":"2022-05-05T16:46:15.865259Z","iopub.status.idle":"2022-05-05T16:46:15.872727Z","shell.execute_reply.started":"2022-05-05T16:46:15.865198Z","shell.execute_reply":"2022-05-05T16:46:15.872010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def my_model3():\n    model=Sequential()\n    model.add( Conv2D(filters=32, kernel_size=(3,3), strides=(1,1), padding='valid', activation=None, use_bias=False, input_shape=(32,32,3)) )\n    model.add(BatchNormalization())\n    model.add(Activation('relu'))\n\n    model.add( Conv2D(filters=64, kernel_size=(3,3), strides=(1,1), padding='valid', activation=None, use_bias=False) )\n    model.add(BatchNormalization())\n    model.add(Activation('relu'))\n\n    model.add( Conv2D(filters=128, kernel_size=(3,3), strides=(1,1), padding='valid', activation=None, use_bias=False) )\n    model.add(BatchNormalization())\n    model.add(Activation('relu'))\n\n\n    model.add(Flatten())\n\n    model.add(Dense(units=10))\n    model.add(BatchNormalization())\n    model.add(Activation('softmax'))\n    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\n    return model\n\ndef my_model5():\n    model=Sequential()\n    model.add( Conv2D(filters=32, kernel_size=(5,5), strides=(1,1), padding='valid', activation=None, use_bias=False, input_shape=(32,32,3)) )\n    model.add(BatchNormalization())\n    model.add(Activation('relu'))\n\n    model.add( Conv2D(filters=64, kernel_size=(5,5), strides=(1,1), padding='valid', activation=None, use_bias=False) )\n    model.add(BatchNormalization())\n    model.add(Activation('relu'))\n\n    model.add( Conv2D(filters=128, kernel_size=(5,5), strides=(1,1), padding='valid', activation=None, use_bias=False) )\n    model.add(BatchNormalization())\n    model.add(Activation('relu'))\n\n    model.add(Flatten())\n\n    model.add(Dense(units=10))\n    model.add(BatchNormalization())\n    model.add(Activation('softmax'))\n    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\n    return model\n\ndef my_model7():\n    model=Sequential()\n    model.add( Conv2D(filters=32, kernel_size=(7,7), strides=(1,1), padding='valid', activation=None, use_bias=False, input_shape=(32,32,3)) )\n    model.add(BatchNormalization())\n    model.add(Activation('relu'))\n\n    model.add( Conv2D(filters=48, kernel_size=(7,7), strides=(1,1), padding='valid', activation=None, use_bias=False) )\n    model.add(BatchNormalization())\n    model.add(Activation('relu'))\n\n    model.add( Conv2D(filters=64, kernel_size=(7,7), strides=(1,1), padding='valid', activation=None, use_bias=False) )\n    model.add(BatchNormalization())\n    model.add(Activation('relu'))\n\n   \n    model.add(Flatten())\n\n    model.add(Dense(units=10))\n    model.add(BatchNormalization())\n    model.add(Activation('softmax'))\n    model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])\n    return model\n","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:15.874243Z","iopub.execute_input":"2022-05-05T16:46:15.874492Z","iopub.status.idle":"2022-05-05T16:46:15.897001Z","shell.execute_reply.started":"2022-05-05T16:46:15.874459Z","shell.execute_reply":"2022-05-05T16:46:15.896190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model3=my_model3()\nmodel5=my_model5()\nmodel7=my_model7()","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:15.898532Z","iopub.execute_input":"2022-05-05T16:46:15.899141Z","iopub.status.idle":"2022-05-05T16:46:18.429171Z","shell.execute_reply.started":"2022-05-05T16:46:15.899056Z","shell.execute_reply":"2022-05-05T16:46:18.428483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.keras.utils.plot_model(model3,show_shapes=True)","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2022-05-05T16:46:18.430472Z","iopub.execute_input":"2022-05-05T16:46:18.430728Z","iopub.status.idle":"2022-05-05T16:46:19.346288Z","shell.execute_reply.started":"2022-05-05T16:46:18.430694Z","shell.execute_reply":"2022-05-05T16:46:19.345399Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_generator.shape","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:19.347741Z","iopub.execute_input":"2022-05-05T16:46:19.348556Z","iopub.status.idle":"2022-05-05T16:46:19.353119Z","shell.execute_reply.started":"2022-05-05T16:46:19.348513Z","shell.execute_reply":"2022-05-05T16:46:19.352275Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hiistory3 = model3.fit(train_generator, epochs=25,  callbacks=[early_stopping_callback, reduceLROnPlateau],workers=8, use_multiprocessing=True, verbose=1, validation_data=val_generator)\nhiistory5 = model5.fit(train_generator, epochs=25,  callbacks=[early_stopping_callback, reduceLROnPlateau],workers=8, use_multiprocessing=True, verbose=1, validation_data=val_generator)\nhiistory7 = model7.fit(train_generator, epochs=25,  callbacks=[early_stopping_callback, reduceLROnPlateau],workers=8, use_multiprocessing=True, verbose=1, validation_data=val_generator)","metadata":{"execution":{"iopub.status.busy":"2022-05-05T16:46:19.354689Z","iopub.execute_input":"2022-05-05T16:46:19.355200Z","iopub.status.idle":"2022-05-05T17:10:56.931662Z","shell.execute_reply.started":"2022-05-05T16:46:19.355157Z","shell.execute_reply":"2022-05-05T17:10:56.930702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# #save the previous model in download \n# path = %pwd\n# model3.save_weights(path)\n# model5.save_weights(path)\n# model7.save_weights(path)\n","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:10:56.934510Z","iopub.execute_input":"2022-05-05T17:10:56.935211Z","iopub.status.idle":"2022-05-05T17:10:56.961753Z","shell.execute_reply.started":"2022-05-05T17:10:56.935169Z","shell.execute_reply":"2022-05-05T17:10:56.955794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd temp","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:10:56.963895Z","iopub.execute_input":"2022-05-05T17:10:56.985398Z","iopub.status.idle":"2022-05-05T17:10:57.020356Z","shell.execute_reply.started":"2022-05-05T17:10:56.985355Z","shell.execute_reply":"2022-05-05T17:10:57.016121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:10:57.021582Z","iopub.execute_input":"2022-05-05T17:10:57.021815Z","iopub.status.idle":"2022-05-05T17:10:57.950565Z","shell.execute_reply.started":"2022-05-05T17:10:57.021784Z","shell.execute_reply":"2022-05-05T17:10:57.949759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%pwd","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:10:57.953216Z","iopub.execute_input":"2022-05-05T17:10:57.953494Z","iopub.status.idle":"2022-05-05T17:10:57.959995Z","shell.execute_reply.started":"2022-05-05T17:10:57.953464Z","shell.execute_reply":"2022-05-05T17:10:57.959246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd ..","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:10:57.961432Z","iopub.execute_input":"2022-05-05T17:10:57.962065Z","iopub.status.idle":"2022-05-05T17:10:57.971803Z","shell.execute_reply.started":"2022-05-05T17:10:57.962012Z","shell.execute_reply":"2022-05-05T17:10:57.971062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import py7zr\n\narchive = py7zr.SevenZipFile('../kaggle/input/cifar-10/test.7z', mode='r')\narchive.extractall(path='../kaggle/temp')","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:10:57.973205Z","iopub.execute_input":"2022-05-05T17:10:57.973639Z","iopub.status.idle":"2022-05-05T17:26:30.758345Z","shell.execute_reply.started":"2022-05-05T17:10:57.973597Z","shell.execute_reply":"2022-05-05T17:26:30.757524Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd ../kaggle/temp","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:26:30.759510Z","iopub.execute_input":"2022-05-05T17:26:30.759779Z","iopub.status.idle":"2022-05-05T17:26:30.771485Z","shell.execute_reply.started":"2022-05-05T17:26:30.759736Z","shell.execute_reply":"2022-05-05T17:26:30.764536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%pwd","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:26:30.774266Z","iopub.execute_input":"2022-05-05T17:26:30.774721Z","iopub.status.idle":"2022-05-05T17:26:31.541485Z","shell.execute_reply.started":"2022-05-05T17:26:30.774675Z","shell.execute_reply":"2022-05-05T17:26:31.540735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:26:31.542648Z","iopub.execute_input":"2022-05-05T17:26:31.543117Z","iopub.status.idle":"2022-05-05T17:26:32.282811Z","shell.execute_reply.started":"2022-05-05T17:26:31.543079Z","shell.execute_reply":"2022-05-05T17:26:32.281940Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.mkdir('test_dir')","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:26:32.284499Z","iopub.execute_input":"2022-05-05T17:26:32.284780Z","iopub.status.idle":"2022-05-05T17:26:32.290657Z","shell.execute_reply.started":"2022-05-05T17:26:32.284745Z","shell.execute_reply":"2022-05-05T17:26:32.289706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\n\n# absolute path\nsrc_path = 'test'\ndst_path = 'test_dir'\nshutil.move(src_path, dst_path)","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:26:32.292328Z","iopub.execute_input":"2022-05-05T17:26:32.292710Z","iopub.status.idle":"2022-05-05T17:26:32.300849Z","shell.execute_reply.started":"2022-05-05T17:26:32.292624Z","shell.execute_reply":"2022-05-05T17:26:32.300162Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:26:32.302017Z","iopub.execute_input":"2022-05-05T17:26:32.302900Z","iopub.status.idle":"2022-05-05T17:26:33.037542Z","shell.execute_reply.started":"2022-05-05T17:26:32.302862Z","shell.execute_reply":"2022-05-05T17:26:33.036706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_datagen = ImageDataGenerator(featurewise_center=False,\n                                  samplewise_center=False,\n                                  featurewise_std_normalization=False,\n                                  samplewise_std_normalization=False,\n                                  zca_whitening=False,\n#                                   rotation_range=10,\n#                                   zoom_range=0.1,\n#                                   width_shift_range=0.1,\n#                                   height_shift_range=0.1,\n                                  horizontal_flip=False,\n                                  vertical_flip=False\n                                  )\n\ntest_generator = test_datagen.flow_from_directory(\n    directory=r\"./test_dir/\",\n    target_size=(32, 32),\n    color_mode=\"rgb\",\n    batch_size=32,\n    class_mode=\"categorical\",\n    shuffle=True,\n    seed=42\n)","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:26:33.039323Z","iopub.execute_input":"2022-05-05T17:26:33.039839Z","iopub.status.idle":"2022-05-05T17:26:43.094957Z","shell.execute_reply.started":"2022-05-05T17:26:33.039793Z","shell.execute_reply":"2022-05-05T17:26:43.092058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label3 = model3.predict(test_generator)\nlabel5 = model5.predict(test_generator)\nlabel7 = model7.predict(test_generator)\nlabel=(label3+label5+label7)/3.","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:26:43.102031Z","iopub.execute_input":"2022-05-05T17:26:43.102330Z","iopub.status.idle":"2022-05-05T17:31:06.542124Z","shell.execute_reply.started":"2022-05-05T17:26:43.102294Z","shell.execute_reply":"2022-05-05T17:31:06.540872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_label_list = []\nfor i in label:\n    final_label_list.append(np.argmax(i))\nprint(final_label_list[:10])\n# print(len(final_label_list))","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:31:06.543367Z","iopub.execute_input":"2022-05-05T17:31:06.543653Z","iopub.status.idle":"2022-05-05T17:31:07.837608Z","shell.execute_reply.started":"2022-05-05T17:31:06.543617Z","shell.execute_reply":"2022-05-05T17:31:07.836850Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%pwd","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:31:07.838830Z","iopub.execute_input":"2022-05-05T17:31:07.839099Z","iopub.status.idle":"2022-05-05T17:31:07.848608Z","shell.execute_reply.started":"2022-05-05T17:31:07.839061Z","shell.execute_reply":"2022-05-05T17:31:07.847254Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd ../kaggle/working","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:31:07.849910Z","iopub.execute_input":"2022-05-05T17:31:07.850183Z","iopub.status.idle":"2022-05-05T17:31:07.856848Z","shell.execute_reply.started":"2022-05-05T17:31:07.850138Z","shell.execute_reply":"2022-05-05T17:31:07.855981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data= {\n    'ImageId':list(range(1,300001)),\n    'Label':final_label_list\n}\n# print(data)\ndf = pd.DataFrame(data).set_index('ImageId')\ndf\n","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:31:07.858242Z","iopub.execute_input":"2022-05-05T17:31:07.858505Z","iopub.status.idle":"2022-05-05T17:31:08.170870Z","shell.execute_reply.started":"2022-05-05T17:31:07.858471Z","shell.execute_reply":"2022-05-05T17:31:08.170106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv('submission1.csv')","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:31:08.172296Z","iopub.execute_input":"2022-05-05T17:31:08.172775Z","iopub.status.idle":"2022-05-05T17:31:08.751928Z","shell.execute_reply.started":"2022-05-05T17:31:08.172731Z","shell.execute_reply":"2022-05-05T17:31:08.751102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dict1 = {\n    0 :'airplane',\n    1:'automobile',\n    2:'bird',\n    3:'cat',\n    4:'deer',\n    5:'dog',\n    6:'frog',\n    7:'horse',\n    8:'ship',\n    9:'truck'\n}\n\nprint(df.head())\n\ndf.Label = df.Label.map(dict1)\n\nlist_ = df.Label\n","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:31:08.753290Z","iopub.execute_input":"2022-05-05T17:31:08.753572Z","iopub.status.idle":"2022-05-05T17:31:08.779559Z","shell.execute_reply.started":"2022-05-05T17:31:08.753535Z","shell.execute_reply":"2022-05-05T17:31:08.778628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"maxLen = [i for i in range(1, len(list_)+1)]\nmaxLen.sort()\nl = [str(i) for i in maxLen]\nl.sort()\nl = [int(i) for i in l]\n\n\nfinal_test_labels = ['']*300000\n\nk = 1\nfor i in l:\n#     print(i,k)\n    final_test_labels[i-1] = list_[k]\n    k+=1\n","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:37:30.373703Z","iopub.execute_input":"2022-05-05T17:37:30.374285Z","iopub.status.idle":"2022-05-05T17:37:31.977376Z","shell.execute_reply.started":"2022-05-05T17:37:30.374248Z","shell.execute_reply":"2022-05-05T17:37:31.976526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.rename(columns={\"ImageId\":\"id\"},inplace=True)\ndf.rename(columns={\"Label\":\"label\"},inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:37:36.594375Z","iopub.execute_input":"2022-05-05T17:37:36.594646Z","iopub.status.idle":"2022-05-05T17:37:36.603444Z","shell.execute_reply.started":"2022-05-05T17:37:36.594607Z","shell.execute_reply":"2022-05-05T17:37:36.602551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv('Submission2.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-05-05T17:37:39.126681Z","iopub.execute_input":"2022-05-05T17:37:39.126980Z","iopub.status.idle":"2022-05-05T17:37:39.485957Z","shell.execute_reply.started":"2022-05-05T17:37:39.126948Z","shell.execute_reply":"2022-05-05T17:37:39.485223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}