{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Блокнот без интернета"},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","execution":{"iopub.execute_input":"2020-11-20T14:05:04.947517Z","iopub.status.busy":"2020-11-20T14:05:04.946866Z","iopub.status.idle":"2020-11-20T14:05:09.799969Z","shell.execute_reply":"2020-11-20T14:05:09.798822Z"},"papermill":{"duration":4.870375,"end_time":"2020-11-20T14:05:09.800093","exception":false,"start_time":"2020-11-20T14:05:04.929718","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"import os\nimport glob\nimport math\nimport numpy as np \nimport pandas as pd \nimport tensorflow as tf\nimport tensorflow.keras.backend as K\nimport matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-11-20T14:05:09.871108Z","iopub.status.busy":"2020-11-20T14:05:09.870001Z","iopub.status.idle":"2020-11-20T14:05:09.899021Z","shell.execute_reply":"2020-11-20T14:05:09.89851Z"},"papermill":{"duration":0.046204,"end_time":"2020-11-20T14:05:09.899123","exception":false,"start_time":"2020-11-20T14:05:09.852919","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"sub = pd.read_csv('../input/cassava-leaf-disease-classification/sample_submission.csv', index_col=0)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-11-20T14:05:09.929454Z","iopub.status.busy":"2020-11-20T14:05:09.928615Z","iopub.status.idle":"2020-11-20T14:05:09.931774Z","shell.execute_reply":"2020-11-20T14:05:09.931178Z"},"papermill":{"duration":0.020552,"end_time":"2020-11-20T14:05:09.931883","exception":false,"start_time":"2020-11-20T14:05:09.911331","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"fs = sub.index","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-11-20T14:05:10.001578Z","iopub.status.busy":"2020-11-20T14:05:10.000773Z","iopub.status.idle":"2020-11-20T14:05:10.003267Z","shell.execute_reply":"2020-11-20T14:05:10.003931Z"},"papermill":{"duration":0.022204,"end_time":"2020-11-20T14:05:10.004048","exception":false,"start_time":"2020-11-20T14:05:09.981844","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"def read_tfrecord(filename):\n    filename = tf.strings.join([\"../input/cassava-leaf-disease-classification/test_images/\", filename])\n    b = tf.io.read_file(filename)\n    image = tf.image.decode_jpeg(b)\n    image = tf.cast(image, tf.float32) / 255.0\n    return image","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-11-20T14:05:12.352334Z","iopub.status.busy":"2020-11-20T14:05:10.133362Z","iopub.status.idle":"2020-11-20T14:05:13.330306Z","shell.execute_reply":"2020-11-20T14:05:13.32961Z"},"papermill":{"duration":3.217724,"end_time":"2020-11-20T14:05:13.330464","exception":false,"start_time":"2020-11-20T14:05:10.11274","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"AUTO = tf.data.experimental.AUTOTUNE\n\ndataset = tf.data.Dataset.from_tensor_slices(fs)\ndataset = dataset.map(read_tfrecord, num_parallel_calls=AUTO)\ndataset = dataset.prefetch(AUTO)\ndataset = dataset.batch(1)\n","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-11-20T14:05:35.734139Z","iopub.status.busy":"2020-11-20T14:05:35.73324Z","iopub.status.idle":"2020-11-20T14:05:40.27155Z","shell.execute_reply":"2020-11-20T14:05:40.270908Z"},"papermill":{"duration":4.624606,"end_time":"2020-11-20T14:05:40.271699","exception":false,"start_time":"2020-11-20T14:05:35.647093","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"model = tf.keras.models.load_model('../input/cassava-leaf-disease-classification-resnet50/resnet50.h5')\n# model.summary(line_length=130)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"for i, image in enumerate(dataset.as_numpy_iterator()):\n    ps = []\n    ps.append(model.predict(image)[0])    \n    ps = np.mean(ps, axis=0)\n    sub.iloc[i, 0] = np.argmax(ps)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sub.to_csv('submission.csv')","execution_count":null,"outputs":[]},{"metadata":{"papermill":{"duration":4.496823,"end_time":"2020-11-20T16:09:54.281886","exception":false,"start_time":"2020-11-20T16:09:49.785063","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"sub","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}