{"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        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-09-25T16:44:54.264623Z","iopub.execute_input":"2022-09-25T16:44:54.264979Z","iopub.status.idle":"2022-09-25T16:45:07.493234Z","shell.execute_reply.started":"2022-09-25T16:44:54.264946Z","shell.execute_reply":"2022-09-25T16:45:07.492246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.preprocessing.image import ImageDataGenerator\nfrom tensorflow.keras.layers import Dense, Activation, Flatten, Dropout, BatchNormalization,Input\nfrom tensorflow.keras.layers import Conv2D, MaxPooling2D\nfrom tensorflow.keras import regularizers, optimizers,Model,applications\nimport pandas as pd\nimport numpy as np","metadata":{"execution":{"iopub.status.busy":"2022-09-25T16:53:32.989619Z","iopub.execute_input":"2022-09-25T16:53:32.990845Z","iopub.status.idle":"2022-09-25T16:53:32.998867Z","shell.execute_reply.started":"2022-09-25T16:53:32.990798Z","shell.execute_reply":"2022-09-25T16:53:32.997788Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.read_csv(\"../input/happy-whale-and-dolphin/train.csv\")\ntest=pd.read_csv(\"../input/happy-whale-and-dolphin/sample_submission.csv\")\ndatagen=ImageDataGenerator(rescale=1./255.,validation_split=0.25)","metadata":{"execution":{"iopub.status.busy":"2022-09-25T16:53:35.483306Z","iopub.execute_input":"2022-09-25T16:53:35.483693Z","iopub.status.idle":"2022-09-25T16:53:35.568466Z","shell.execute_reply.started":"2022-09-25T16:53:35.483661Z","shell.execute_reply":"2022-09-25T16:53:35.567558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_gen=datagen.flow_from_dataframe(train,directory=\"../input/happy-whale-and-dolphin/train_images\",x_col=\"image\",y_col=\"species\",subset='training',color_mode='rgb',target_size=(224,224))\ntest_gen=datagen.flow_from_dataframe(test,directory=\"../input/happy-whale-and-dolphin/test_images\",x_col=\"image\",y_col=None,class_mode=None,color_mode='rgb',target_size=(224,224))","metadata":{"execution":{"iopub.status.busy":"2022-09-25T16:59:58.513824Z","iopub.execute_input":"2022-09-25T16:59:58.514196Z","iopub.status.idle":"2022-09-25T17:00:31.251984Z","shell.execute_reply.started":"2022-09-25T16:59:58.514164Z","shell.execute_reply":"2022-09-25T17:00:31.250935Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shape=train_gen.image_shape\noutput_shape=30","metadata":{"execution":{"iopub.status.busy":"2022-09-25T17:00:47.420193Z","iopub.execute_input":"2022-09-25T17:00:47.420877Z","iopub.status.idle":"2022-09-25T17:00:47.425436Z","shell.execute_reply.started":"2022-09-25T17:00:47.420838Z","shell.execute_reply":"2022-09-25T17:00:47.424398Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def model_create(input_shape,output_shape):\n    pretrained_model = applications.MobileNetV2(\n    include_top=False,\n    weights='imagenet',\n    pooling='avg')\n    pretrained_model.trainable = False\n    inputs=Input(input_shape)\n    features=pretrained_model(inputs)\n    drops2=Dropout(0.3)(features)\n    dense=Dense(100,'relu')(drops2)\n    output=Dense(30,\"softmax\")(dense)\n    model=Model(inputs,output)\n    model.compile('adam',loss='categorical_crossentropy',metrics='accuracy')\n    print(model.summary())\n    return model","metadata":{"execution":{"iopub.status.busy":"2022-09-25T17:01:41.843580Z","iopub.execute_input":"2022-09-25T17:01:41.844024Z","iopub.status.idle":"2022-09-25T17:01:41.856216Z","shell.execute_reply.started":"2022-09-25T17:01:41.843981Z","shell.execute_reply":"2022-09-25T17:01:41.855222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"WandD_Model=model_create(shape,output_shape)","metadata":{"execution":{"iopub.status.busy":"2022-09-25T17:01:42.810453Z","iopub.execute_input":"2022-09-25T17:01:42.810876Z","iopub.status.idle":"2022-09-25T17:01:44.343076Z","shell.execute_reply.started":"2022-09-25T17:01:42.810837Z","shell.execute_reply":"2022-09-25T17:01:44.342090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"WandD_Model.fit_generator(train_gen,epochs=4)","metadata":{"execution":{"iopub.status.busy":"2022-09-25T17:01:56.691433Z","iopub.execute_input":"2022-09-25T17:01:56.691824Z","iopub.status.idle":"2022-09-25T17:03:38.042880Z","shell.execute_reply.started":"2022-09-25T17:01:56.691789Z","shell.execute_reply":"2022-09-25T17:03:38.039807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}