{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport tensorflow as tf\n\nfrom tensorflow.keras.applications import EfficientNetB3\nfrom tensorflow.keras.applications.efficientnet import preprocess_input\nAUTOTUNE = tf.data.experimental.AUTOTUNE\n\nimport matplotlib.pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"BASE_DIR = '../input/cassava-leaf-disease-classification'\nTRAIN_IMAGES_FOLDER = os.path.join(BASE_DIR, 'train_images')\nTEST_IMAGES_FOLDER = os.path.join(BASE_DIR, 'test_images')\n\ndf = pd.read_csv(os.path.join(BASE_DIR, 'train.csv'))\ndf.image_id = BASE_DIR + '/train_images/' + df.image_id","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def data_pipeline(image_file):\n    image = tf.io.read_file(image_file)\n    image = tf.io.decode_jpeg(image, channels=3)\n    image = tf.image.resize(image, IMG_SHAPE)\n    image = preprocess_input(image)\n    return image","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def create_model(input_shape):\n    base_model = EfficientNetB3(\n        weights='imagenet',\n        include_top=False,\n        input_shape = tuple(input_shape + [3]))\n    base_model.trainable = False\n\n    x = base_model.output\n    outputs = tf.keras.layers.GlobalAveragePooling2D()(x)\n    \n    model = tf.keras.Model(inputs=base_model.input, outputs=outputs)\n    return model","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"IMG_SHAPE = [300, 300]\nmodel = create_model(IMG_SHAPE)\n\ndataset = tf.data.Dataset.from_tensor_slices(df.image_id)\ndataset = dataset.map(data_pipeline, num_parallel_calls=AUTOTUNE)\ndataset = dataset.batch(128)\n\nfeatures = model.predict(dataset)\nnp.save('features.npy', features)","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}