{"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":"!pip install py7zr\nfrom py7zr import unpack_7zarchive\nimport shutil\nshutil.register_unpack_format('7zip', ['.7z'], unpack_7zarchive)\n\n# unzitensorflow.keras.preprocessingshutil.unpack_archive('../input/cifar-10/train.7z')\n\n\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-10-11T16:22:03.045018Z","iopub.execute_input":"2021-10-11T16:22:03.04527Z","iopub.status.idle":"2021-10-11T16:22:13.019915Z","shell.execute_reply.started":"2021-10-11T16:22:03.045242Z","shell.execute_reply":"2021-10-11T16:22:13.019178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shutil.unpack_archive('../input/cifar-10/test.7z')\nshutil.unpack_archive('../input/cifar-10/train.7z')","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:22:13.021871Z","iopub.execute_input":"2021-10-11T16:22:13.022132Z","iopub.status.idle":"2021-10-11T16:38:33.797691Z","shell.execute_reply.started":"2021-10-11T16:22:13.022097Z","shell.execute_reply":"2021-10-11T16:38:33.796786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\n%matplotlib inline\nimport os\nimport tensorflow.keras as keras\nfrom tensorflow.keras.preprocessing.image import load_img ,ImageDataGenerator\nfrom tensorflow.keras.models import Model ,Sequential \nfrom tensorflow.keras.layers import Conv2D, BatchNormalization, MaxPooling2D, Dropout, Dense,SeparableConv2D ,Flatten","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:38:33.799145Z","iopub.execute_input":"2021-10-11T16:38:33.799418Z","iopub.status.idle":"2021-10-11T16:38:38.123626Z","shell.execute_reply.started":"2021-10-11T16:38:33.799386Z","shell.execute_reply":"2021-10-11T16:38:38.122871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# load data","metadata":{}},{"cell_type":"code","source":"train_dir=os.listdir('./train')\ntrain_dir_len = len(train_dir)\nprint('Length :\\t',\n      train_dir_len)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:38:38.125422Z","iopub.execute_input":"2021-10-11T16:38:38.125645Z","iopub.status.idle":"2021-10-11T16:38:38.170627Z","shell.execute_reply.started":"2021-10-11T16:38:38.125613Z","shell.execute_reply":"2021-10-11T16:38:38.169877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels = pd.read_csv('../input/cifar-10/trainLabels.csv')\ntrain_images = pd.DataFrame(columns=['id','labels','path'] ,dtype =str)\ntest_labels =pd.read_csv('../input/cifar-10/sampleSubmission.csv')","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:38:38.173384Z","iopub.execute_input":"2021-10-11T16:38:38.173608Z","iopub.status.idle":"2021-10-11T16:38:38.295592Z","shell.execute_reply.started":"2021-10-11T16:38:38.173583Z","shell.execute_reply":"2021-10-11T16:38:38.294778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_labels","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:38:38.29676Z","iopub.execute_input":"2021-10-11T16:38:38.297047Z","iopub.status.idle":"2021-10-11T16:38:38.321361Z","shell.execute_reply.started":"2021-10-11T16:38:38.297014Z","shell.execute_reply":"2021-10-11T16:38:38.320561Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.random.set_seed(\n    32\n)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:38:38.32256Z","iopub.execute_input":"2021-10-11T16:38:38.322882Z","iopub.status.idle":"2021-10-11T16:38:38.327044Z","shell.execute_reply.started":"2021-10-11T16:38:38.322837Z","shell.execute_reply":"2021-10-11T16:38:38.326256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_root = './train/'\nfor i in range( 0 , train_dir_len):\n    path = train_root+str(i+1)+'.png'\n    if os.path.exists(path):\n        \n        train_images=train_images.append([\n         {   'id' :train_labels['id'].iloc[i],\n            'label' :train_labels['label'].iloc[i],\n            'path' :str(i+1)+'.png'}\n        ])","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:38:38.328197Z","iopub.execute_input":"2021-10-11T16:38:38.32872Z","iopub.status.idle":"2021-10-11T16:42:59.27811Z","shell.execute_reply.started":"2021-10-11T16:38:38.328684Z","shell.execute_reply":"2021-10-11T16:42:59.277378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images=train_images.sort_values(by=['id'])\n\ntrain_images.head(10)\ntrain_images.drop(['labels'] ,axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:42:59.279337Z","iopub.execute_input":"2021-10-11T16:42:59.279591Z","iopub.status.idle":"2021-10-11T16:42:59.329086Z","shell.execute_reply.started":"2021-10-11T16:42:59.27956Z","shell.execute_reply":"2021-10-11T16:42:59.328282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']\nfor name in class_names :\n    index = class_names.index(name)\n    train_images.loc[train_images['label'] ==name ,'label'] =str(index)\ndisplay_groupby = train_images.groupby(['label']).count()\ndisplay_groupby.head(10)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:42:59.332137Z","iopub.execute_input":"2021-10-11T16:42:59.332347Z","iopub.status.idle":"2021-10-11T16:42:59.428655Z","shell.execute_reply.started":"2021-10-11T16:42:59.332324Z","shell.execute_reply":"2021-10-11T16:42:59.427867Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images=train_images.drop(['labels'] ,axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:42:59.43003Z","iopub.execute_input":"2021-10-11T16:42:59.430312Z","iopub.status.idle":"2021-10-11T16:42:59.43658Z","shell.execute_reply.started":"2021-10-11T16:42:59.430266Z","shell.execute_reply":"2021-10-11T16:42:59.435734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size = 64 \nnum_class= 10\n","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:42:59.438081Z","iopub.execute_input":"2021-10-11T16:42:59.438527Z","iopub.status.idle":"2021-10-11T16:42:59.445616Z","shell.execute_reply.started":"2021-10-11T16:42:59.438489Z","shell.execute_reply":"2021-10-11T16:42:59.444984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_labels['id'] = train_labels['id'].astype(str)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:42:59.446729Z","iopub.execute_input":"2021-10-11T16:42:59.447046Z","iopub.status.idle":"2021-10-11T16:42:59.510423Z","shell.execute_reply.started":"2021-10-11T16:42:59.447012Z","shell.execute_reply":"2021-10-11T16:42:59.509701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:42:59.512262Z","iopub.execute_input":"2021-10-11T16:42:59.512718Z","iopub.status.idle":"2021-10-11T16:42:59.528275Z","shell.execute_reply.started":"2021-10-11T16:42:59.512682Z","shell.execute_reply":"2021-10-11T16:42:59.527628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_l = train_labels[:35000]","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:42:59.529426Z","iopub.execute_input":"2021-10-11T16:42:59.52967Z","iopub.status.idle":"2021-10-11T16:42:59.536393Z","shell.execute_reply.started":"2021-10-11T16:42:59.52964Z","shell.execute_reply":"2021-10-11T16:42:59.535656Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_l = train_labels[35000:]","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:42:59.537804Z","iopub.execute_input":"2021-10-11T16:42:59.53834Z","iopub.status.idle":"2021-10-11T16:42:59.545662Z","shell.execute_reply.started":"2021-10-11T16:42:59.538263Z","shell.execute_reply":"2021-10-11T16:42:59.545049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_generator = ImageDataGenerator(rescale=1/255. ,rotation_range=True , validation_split=.3)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:45:38.264215Z","iopub.execute_input":"2021-10-11T16:45:38.264781Z","iopub.status.idle":"2021-10-11T16:45:38.269142Z","shell.execute_reply.started":"2021-10-11T16:45:38.264743Z","shell.execute_reply":"2021-10-11T16:45:38.268277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_generator =  data_generator.flow_from_dataframe(dataframe=train_images,directory='./train',\n                                                    x_col='path',\n                                                    y_col='label',\n                                                    subset='training',\n                                                    batch_size=batch_size,\n                                                    \n                                                    target_size=(32,32),\n                                                    class_mode='categorical')","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:45:39.774793Z","iopub.execute_input":"2021-10-11T16:45:39.775381Z","iopub.status.idle":"2021-10-11T16:45:40.196227Z","shell.execute_reply.started":"2021-10-11T16:45:39.77534Z","shell.execute_reply":"2021-10-11T16:45:40.195476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_generator = data_generator.flow_from_dataframe(dataframe=train_images,directory='./train',\n                                                    x_col='path',\n                                                    y_col='label',\n                                                    subset='validation',\n                                                    batch_size=batch_size,\n                                                    shuffle=True,\n                                                    target_size=(32,32),\n                                                    class_mode='categorical')","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:45:40.410882Z","iopub.execute_input":"2021-10-11T16:45:40.411452Z","iopub.status.idle":"2021-10-11T16:45:40.805733Z","shell.execute_reply.started":"2021-10-11T16:45:40.411402Z","shell.execute_reply":"2021-10-11T16:45:40.804966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential()\nmodel.add(SeparableConv2D(32, kernel_size=3, activation='relu', padding='same', input_shape=(32,32,3)))\nmodel.add(BatchNormalization())\nmodel.add(SeparableConv2D(32, kernel_size=3, activation='relu', padding='same'))\nmodel.add(BatchNormalization())\nmodel.add(MaxPooling2D())\nmodel.add(Dropout(0.2))\n\nmodel.add(SeparableConv2D(64, kernel_size=3, activation='relu', padding='same'))\nmodel.add(BatchNormalization())\nmodel.add(SeparableConv2D(64, kernel_size=3, activation='relu', padding='same'))\nmodel.add(BatchNormalization())\nmodel.add(MaxPooling2D())\nmodel.add(Dropout(0.3))\n\nmodel.add(SeparableConv2D(128, kernel_size=3, activation='relu', padding='same'))\nmodel.add(BatchNormalization())\nmodel.add(SeparableConv2D(128, kernel_size=3, activation='relu', padding='same'))\nmodel.add(BatchNormalization())\n\nmodel.add(MaxPooling2D())\nmodel.add(Dropout(0.4))\n\n\n\nmodel.add(SeparableConv2D(128,kernel_size=(4,4),strides=(1,1),padding='valid',activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(SeparableConv2D(128,kernel_size=(1,1),strides=(1,1)\n                 ,padding='valid',activation='relu'))\nmodel.add(BatchNormalization())\n# model.add(MaxPooling2D())\nmodel.add(Dropout(0.6))\nmodel.add(SeparableConv2D(10,kernel_size=(1,1),strides=(1,1),padding='valid',activation='softmax'))\n\nmodel.add(Flatten())\n\n# model.add(Dense(128, activation='relu'))\n# model.add(BatchNormalization())\n# model.add(Dropout(0.4))\n# model.add(Dense(10, activation='softmax'))\n\nmodel.compile(loss='categorical_crossentropy', optimizer=keras.optimizers.Adam(0.001), metrics=['accuracy'])\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:45:41.113689Z","iopub.execute_input":"2021-10-11T16:45:41.114224Z","iopub.status.idle":"2021-10-11T16:45:43.434187Z","shell.execute_reply.started":"2021-10-11T16:45:41.114189Z","shell.execute_reply":"2021-10-11T16:45:43.433497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"reduce_le = keras.callbacks.ReduceLROnPlateau(monitor=\"val_loss\", patience=5,factor=.7 , min_denta=.00001)\nse = keras.callbacks.EarlyStopping(monitor=\"val_loss\" ,patience=10 ,verbose=1 ,restore_best_weights=True)\nhistory = model.fit(train_generator,epochs=100,validation_data=val_generator ,callbacks=[reduce_le,se] )","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:45:43.435832Z","iopub.execute_input":"2021-10-11T16:45:43.436083Z","iopub.status.idle":"2021-10-11T17:38:05.723685Z","shell.execute_reply.started":"2021-10-11T16:45:43.43605Z","shell.execute_reply":"2021-10-11T17:38:05.722934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"_, ax = plt.subplots(2, 1)\nax[0].plot(history.history['loss'], color='b', label='loss')\nax[0].plot(history.history['val_loss'], color='r', label='val_loss')\nlegend = ax[0].legend(loc='best', shadow=True)\n\nax[1].plot(history.history['accuracy'], color='b', label='accuracy')\nax[1].plot(history.history['val_accuracy'], color='r', label='val_accuracy')\nlegend = ax[1].legend(loc='best', shadow=True)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:38:05.725717Z","iopub.execute_input":"2021-10-11T17:38:05.725982Z","iopub.status.idle":"2021-10-11T17:38:06.065435Z","shell.execute_reply.started":"2021-10-11T17:38:05.725946Z","shell.execute_reply":"2021-10-11T17:38:06.064699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir ./data/\n!mv ./test ./data","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:38:06.066806Z","iopub.execute_input":"2021-10-11T17:38:06.067096Z","iopub.status.idle":"2021-10-11T17:38:07.478246Z","shell.execute_reply.started":"2021-10-11T17:38:06.067061Z","shell.execute_reply":"2021-10-11T17:38:07.474526Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data_generator = ImageDataGenerator(rescale=1./255.)\ntest_generator = test_data_generator.flow_from_directory(directory='./data',\n            batch_size=batch_size,\n            shuffle=False,color_mode='rgb',\n            target_size=(32,32),\n            class_mode=None)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:38:07.484494Z","iopub.execute_input":"2021-10-11T17:38:07.485101Z","iopub.status.idle":"2021-10-11T17:38:16.461279Z","shell.execute_reply.started":"2021-10-11T17:38:07.485056Z","shell.execute_reply":"2021-10-11T17:38:16.460528Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_pre = model.predict(train_generator)\n","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:38:16.462713Z","iopub.execute_input":"2021-10-11T17:38:16.46298Z","iopub.status.idle":"2021-10-11T17:38:39.708094Z","shell.execute_reply.started":"2021-10-11T17:38:16.462947Z","shell.execute_reply":"2021-10-11T17:38:39.707384Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_pre = model.predict(val_generator)\n","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:38:39.709427Z","iopub.execute_input":"2021-10-11T17:38:39.709937Z","iopub.status.idle":"2021-10-11T17:38:50.047764Z","shell.execute_reply.started":"2021-10-11T17:38:39.709899Z","shell.execute_reply":"2021-10-11T17:38:50.046907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction = model.predict(test_generator)\npre_data = pd.DataFrame(data=prediction)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:38:50.051393Z","iopub.execute_input":"2021-10-11T17:38:50.051613Z","iopub.status.idle":"2021-10-11T17:40:11.661592Z","shell.execute_reply.started":"2021-10-11T17:38:50.051587Z","shell.execute_reply":"2021-10-11T17:40:11.660829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2021-10-11T16:43:00.295781Z","iopub.status.idle":"2021-10-11T16:43:00.296186Z","shell.execute_reply.started":"2021-10-11T16:43:00.295967Z","shell.execute_reply":"2021-10-11T16:43:00.295988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']\nfor name in class_names :\n    index = class_names.index(name)\n    train_l.loc[train_l['label'] ==name ,'label'] =str(index)\n    val_l.loc[val_l['label'] ==name ,'label'] =str(index)\n\ndisplay_groupby = train_l.groupby(['label']).count()\ndisplay_groupby.head(10)\n","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:43:08.653256Z","iopub.execute_input":"2021-10-11T17:43:08.653831Z","iopub.status.idle":"2021-10-11T17:43:08.736444Z","shell.execute_reply.started":"2021-10-11T17:43:08.653791Z","shell.execute_reply":"2021-10-11T17:43:08.735751Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"# display_groupby = train_labels.groupby(['label']).count()\n# display_groupby\n","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:40:38.119179Z","iopub.execute_input":"2021-10-11T17:40:38.119771Z","iopub.status.idle":"2021-10-11T17:40:38.123462Z","shell.execute_reply.started":"2021-10-11T17:40:38.119731Z","shell.execute_reply":"2021-10-11T17:40:38.122596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# train_labels['label']=train_labels['label'].astype('int32')\n","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:40:38.364551Z","iopub.execute_input":"2021-10-11T17:40:38.365129Z","iopub.status.idle":"2021-10-11T17:40:38.368615Z","shell.execute_reply.started":"2021-10-11T17:40:38.365092Z","shell.execute_reply":"2021-10-11T17:40:38.367625Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_lab['label']=test_labels['label'].astype('int32')","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:40:39.700005Z","iopub.execute_input":"2021-10-11T17:40:39.700461Z","iopub.status.idle":"2021-10-11T17:40:39.70441Z","shell.execute_reply.started":"2021-10-11T17:40:39.700425Z","shell.execute_reply":"2021-10-11T17:40:39.703325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_l","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:43:24.280673Z","iopub.execute_input":"2021-10-11T17:43:24.280945Z","iopub.status.idle":"2021-10-11T17:43:24.294962Z","shell.execute_reply.started":"2021-10-11T17:43:24.280914Z","shell.execute_reply":"2021-10-11T17:43:24.293918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" train_l=train_l.drop(['id'] ,axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:40:40.110589Z","iopub.execute_input":"2021-10-11T17:40:40.111149Z","iopub.status.idle":"2021-10-11T17:40:40.121063Z","shell.execute_reply.started":"2021-10-11T17:40:40.111117Z","shell.execute_reply":"2021-10-11T17:40:40.120169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" val_l=val_l.drop(['id'] ,axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:40:40.974022Z","iopub.execute_input":"2021-10-11T17:40:40.974275Z","iopub.status.idle":"2021-10-11T17:40:40.981066Z","shell.execute_reply.started":"2021-10-11T17:40:40.974245Z","shell.execute_reply":"2021-10-11T17:40:40.979951Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_l =val_l.astype('int64')\ntrain_l =train_l.astype('int64')","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:43:53.473822Z","iopub.execute_input":"2021-10-11T17:43:53.474094Z","iopub.status.idle":"2021-10-11T17:43:53.482951Z","shell.execute_reply.started":"2021-10-11T17:43:53.474064Z","shell.execute_reply":"2021-10-11T17:43:53.48201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# val_l =val_l*255\n# train_l =train_l*255","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:46:55.672108Z","iopub.execute_input":"2021-10-11T17:46:55.67239Z","iopub.status.idle":"2021-10-11T17:46:55.683327Z","shell.execute_reply.started":"2021-10-11T17:46:55.672359Z","shell.execute_reply":"2021-10-11T17:46:55.681916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_l.head(100)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:46:56.588398Z","iopub.execute_input":"2021-10-11T17:46:56.58909Z","iopub.status.idle":"2021-10-11T17:46:56.602827Z","shell.execute_reply.started":"2021-10-11T17:46:56.589053Z","shell.execute_reply":"2021-10-11T17:46:56.601959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pre_data","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:47:03.330689Z","iopub.execute_input":"2021-10-11T17:47:03.331223Z","iopub.status.idle":"2021-10-11T17:47:03.351268Z","shell.execute_reply.started":"2021-10-11T17:47:03.331182Z","shell.execute_reply":"2021-10-11T17:47:03.350499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from xgboost import XGBClassifier\n\nxgbmodel = XGBClassifier(objective='multi:softprob', \n                      num_class= 10,use_label_encode=False)\nxgbmodel.fit(train_pre, train_l)\nxgbmodel.score(val_pre, val_l)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:47:04.206963Z","iopub.execute_input":"2021-10-11T17:47:04.207414Z","iopub.status.idle":"2021-10-11T17:48:15.930554Z","shell.execute_reply.started":"2021-10-11T17:47:04.207374Z","shell.execute_reply":"2021-10-11T17:48:15.929878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\n\nprediction =xgbmodel.predict(pre_data)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:48:29.511952Z","iopub.execute_input":"2021-10-11T17:48:29.512208Z","iopub.status.idle":"2021-10-11T17:48:35.155112Z","shell.execute_reply.started":"2021-10-11T17:48:29.51218Z","shell.execute_reply":"2021-10-11T17:48:35.154401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# prediction = np.argmax(prediction, axis=1)\nsubmission = pd.DataFrame(columns=['id', 'label'], dtype=str)\nsubmission['label'] = [class_names[int(i)] for i in prediction]\nsubmission['id'] = [ (''.join(filter(str.isdigit, name ))) for name in test_generator.filenames]\n# submission = pd.DataFrame({'id':test_labels['id'],'label':prediction})\nsubmission.sort_values(by=['id'])\nsubmission.head()","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:49:33.627052Z","iopub.execute_input":"2021-10-11T17:49:33.627347Z","iopub.status.idle":"2021-10-11T17:49:34.597345Z","shell.execute_reply.started":"2021-10-11T17:49:33.627295Z","shell.execute_reply":"2021-10-11T17:49:34.596511Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction\n","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:48:58.762217Z","iopub.execute_input":"2021-10-11T17:48:58.763036Z","iopub.status.idle":"2021-10-11T17:48:58.769204Z","shell.execute_reply.started":"2021-10-11T17:48:58.762984Z","shell.execute_reply":"2021-10-11T17:48:58.768249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%rm -rf ./train\n%rm -rf ./data","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:49:50.45879Z","iopub.execute_input":"2021-10-11T17:49:50.459045Z","iopub.status.idle":"2021-10-11T17:50:01.007152Z","shell.execute_reply.started":"2021-10-11T17:49:50.459016Z","shell.execute_reply":"2021-10-11T17:50:01.006181Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2021-10-11T17:50:01.00894Z","iopub.execute_input":"2021-10-11T17:50:01.009218Z","iopub.status.idle":"2021-10-11T17:50:01.543881Z","shell.execute_reply.started":"2021-10-11T17:50:01.009188Z","shell.execute_reply":"2021-10-11T17:50:01.543133Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction","metadata":{"execution":{"iopub.status.busy":"2021-10-11T06:22:00.691012Z","iopub.execute_input":"2021-10-11T06:22:00.691468Z","iopub.status.idle":"2021-10-11T06:22:00.702158Z","shell.execute_reply.started":"2021-10-11T06:22:00.691435Z","shell.execute_reply":"2021-10-11T06:22:00.700823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_labels","metadata":{"execution":{"iopub.status.busy":"2021-10-11T06:22:09.631871Z","iopub.execute_input":"2021-10-11T06:22:09.632144Z","iopub.status.idle":"2021-10-11T06:22:09.644047Z","shell.execute_reply.started":"2021-10-11T06:22:09.632117Z","shell.execute_reply":"2021-10-11T06:22:09.643248Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}