{"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":"2021-07-09T06:14:25.204530Z","iopub.execute_input":"2021-07-09T06:14:25.205013Z","iopub.status.idle":"2021-07-09T06:14:25.223454Z","shell.execute_reply.started":"2021-07-09T06:14:25.204912Z","shell.execute_reply":"2021-07-09T06:14:25.222119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv2D\nfrom tensorflow.keras.layers import MaxPool2D\nfrom tensorflow.keras.optimizers import Adam\n\nfrom tensorflow.keras.layers import Dense, Activation, Dropout, Flatten\nfrom tensorflow.keras.utils import plot_model, to_categorical\nfrom keras.callbacks import TensorBoard\n\nfrom keras.datasets import cifar10","metadata":{"execution":{"iopub.status.busy":"2021-07-09T06:14:25.225409Z","iopub.execute_input":"2021-07-09T06:14:25.225845Z","iopub.status.idle":"2021-07-09T06:14:31.601955Z","shell.execute_reply.started":"2021-07-09T06:14:25.225809Z","shell.execute_reply":"2021-07-09T06:14:31.600845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(X_train, y_train),(X_test, y_test) = cifar10.load_data()","metadata":{"execution":{"iopub.status.busy":"2021-07-09T06:14:31.604099Z","iopub.execute_input":"2021-07-09T06:14:31.604542Z","iopub.status.idle":"2021-07-09T06:14:45.869793Z","shell.execute_reply.started":"2021-07-09T06:14:31.604498Z","shell.execute_reply":"2021-07-09T06:14:45.868755Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# floatに型変換\nX_train = X_train.astype('float32')\nX_test = X_test.astype('float32')\n# 各画素値を正規化\nX_train /= 255.0\nX_test /= 255.0\n\nfrom keras.utils.np_utils import to_categorical\ny_train = to_categorical(y_train, 10)\ny_test = to_categorical(y_test, 10)","metadata":{"execution":{"iopub.status.busy":"2021-07-09T06:14:45.871531Z","iopub.execute_input":"2021-07-09T06:14:45.871884Z","iopub.status.idle":"2021-07-09T06:14:46.219875Z","shell.execute_reply.started":"2021-07-09T06:14:45.871850Z","shell.execute_reply":"2021-07-09T06:14:46.218814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# モデルの定義\nmodel = Sequential()\n\nmodel.add(Conv2D(32,3,input_shape=(32,32,3)))\nmodel.add(Activation('relu'))\nmodel.add(Conv2D(32,3))\nmodel.add(Activation('relu'))\nmodel.add(MaxPool2D(pool_size=(2,2)))\n\nmodel.add(Conv2D(64,3))\nmodel.add(Activation('relu'))\nmodel.add(MaxPool2D(pool_size=(2,2)))\n\nmodel.add(Flatten())\nmodel.add(Dense(1024))\nmodel.add(Activation('relu'))\nmodel.add(Dropout(0.5))\n\nmodel.add(Dense(10, activation='softmax'))\n\nadam = Adam(lr=1e-4)\n\nmodel.compile(optimizer=adam, loss='categorical_crossentropy', metrics=[\"accuracy\"])","metadata":{"execution":{"iopub.status.busy":"2021-07-09T06:14:46.221092Z","iopub.execute_input":"2021-07-09T06:14:46.221414Z","iopub.status.idle":"2021-07-09T06:14:46.410748Z","shell.execute_reply.started":"2021-07-09T06:14:46.221377Z","shell.execute_reply":"2021-07-09T06:14:46.409702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(X_train, y_train, batch_size=128, epochs=1, verbose=1, validation_split=0.1)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# モデルをプロット\nplot_model(model, to_file='./model2.png')","metadata":{"execution":{"iopub.status.busy":"2021-07-09T06:14:46.690371Z","iopub.status.idle":"2021-07-09T06:14:46.690788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_loss, test_acc = model.evaluate(X_test, y_test, verbose=2)\n\nprint('\\nTest accuracy:', test_acc)","metadata":{"execution":{"iopub.status.busy":"2021-07-09T06:14:46.692103Z","iopub.status.idle":"2021-07-09T06:14:46.692683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}