{"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":"import os\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nimport tensorflow as tf\nimport tensorflow_hub as hub\nfrom tensorflow.keras.layers import Dense,Dropout\nfrom tensorflow.keras.models import Sequential,Model\n\nprint(\"TF version:\", tf.__version__)\nprint(\"Hub version:\", hub.__version__)\nprint(\"GPU is\", \"available\" if tf.config.list_physical_devices('GPU') else \"NOT AVAILABLE\")","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-09-07T07:03:55.172011Z","iopub.execute_input":"2021-09-07T07:03:55.172412Z","iopub.status.idle":"2021-09-07T07:03:57.132264Z","shell.execute_reply.started":"2021-09-07T07:03:55.172327Z","shell.execute_reply":"2021-09-07T07:03:57.130823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DATA_DIR = '../input/plant-pathology-2021-fgvc8/'\ntrain_data = pd.read_csv(DATA_DIR+'train.csv')\ntrain_data.shape","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:03:58.251790Z","iopub.execute_input":"2021-09-07T07:03:58.252119Z","iopub.status.idle":"2021-09-07T07:03:58.280454Z","shell.execute_reply.started":"2021-09-07T07:03:58.252086Z","shell.execute_reply":"2021-09-07T07:03:58.279485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:03:59.266069Z","iopub.execute_input":"2021-09-07T07:03:59.266438Z","iopub.status.idle":"2021-09-07T07:03:59.282829Z","shell.execute_reply.started":"2021-09-07T07:03:59.266406Z","shell.execute_reply":"2021-09-07T07:03:59.281989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.info()","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:03:59.976101Z","iopub.execute_input":"2021-09-07T07:03:59.976471Z","iopub.status.idle":"2021-09-07T07:03:59.992874Z","shell.execute_reply.started":"2021-09-07T07:03:59.976439Z","shell.execute_reply":"2021-09-07T07:03:59.991908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data['labels'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:04:00.222376Z","iopub.execute_input":"2021-09-07T07:04:00.222693Z","iopub.status.idle":"2021-09-07T07:04:00.233824Z","shell.execute_reply.started":"2021-09-07T07:04:00.222664Z","shell.execute_reply":"2021-09-07T07:04:00.232817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# unique labels -> 6 ['scab','healthy','frog_eye_leaf_spot','rust','complex','powdery_mildew']\nlabel_vals = ['scab','healthy','frog_eye_leaf_spot','rust','complex','powdery_mildew']\nlabels = train_data['labels'].values\noh_labels = np.zeros((len(labels),len(label_vals)))\nfor i,label in enumerate(labels):\n    ls = label.split()\n    for l in ls:\n        if l not in label_vals:\n            raise Exception('Label not found')\n        oh_labels[i,label_vals.index(l)] = 1\n        \nprint(labels[:5])\ntrain_df = pd.concat([train_data['image'],pd.DataFrame(oh_labels,columns = label_vals)],axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:04:00.925616Z","iopub.execute_input":"2021-09-07T07:04:00.925934Z","iopub.status.idle":"2021-09-07T07:04:00.958107Z","shell.execute_reply.started":"2021-09-07T07:04:00.925905Z","shell.execute_reply":"2021-09-07T07:04:00.957127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:04:01.165804Z","iopub.execute_input":"2021-09-07T07:04:01.166129Z","iopub.status.idle":"2021-09-07T07:04:01.181489Z","shell.execute_reply.started":"2021-09-07T07:04:01.166099Z","shell.execute_reply":"2021-09-07T07:04:01.180493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# @param ['efficientnetv2-s', 'efficientnetv2-m', 'efficientnetv2-l', 'efficientnetv2-s-21k', 'efficientnetv2-m-21k', 'efficientnetv2-l-21k', 'efficientnetv2-xl-21k', 'efficientnetv2-b0-21k', 'efficientnetv2-b1-21k', 'efficientnetv2-b2-21k', 'efficientnetv2-b3-21k', 'efficientnetv2-s-21k-ft1k', 'efficientnetv2-m-21k-ft1k', 'efficientnetv2-l-21k-ft1k', 'efficientnetv2-xl-21k-ft1k', 'efficientnetv2-b0-21k-ft1k', 'efficientnetv2-b1-21k-ft1k', 'efficientnetv2-b2-21k-ft1k', 'efficientnetv2-b3-21k-ft1k', 'efficientnetv2-b0', 'efficientnetv2-b1', 'efficientnetv2-b2', 'efficientnetv2-b3', 'efficientnet_b0', 'efficientnet_b1', 'efficientnet_b2', 'efficientnet_b3', 'efficientnet_b4', 'efficientnet_b5', 'efficientnet_b6', 'efficientnet_b7', 'bit_s-r50x1', 'inception_v3', 'inception_resnet_v2', 'resnet_v1_50', 'resnet_v1_101', 'resnet_v1_152', 'resnet_v2_50', 'resnet_v2_101', 'resnet_v2_152', 'nasnet_large', 'nasnet_mobile', 'pnasnet_large', 'mobilenet_v2_100_224', 'mobilenet_v2_130_224', 'mobilenet_v2_140_224', 'mobilenet_v3_small_100_224', 'mobilenet_v3_small_075_224', 'mobilenet_v3_large_100_224', 'mobilenet_v3_large_075_224']\n\nmodel_handle_map = {\n  \"efficientnetv2-s\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet1k_s/feature_vector/2\",\n  \"efficientnetv2-m\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet1k_m/feature_vector/2\",\n  \"efficientnetv2-l\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet1k_l/feature_vector/2\",\n  \"efficientnetv2-s-21k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_s/feature_vector/2\",\n  \"efficientnetv2-m-21k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_m/feature_vector/2\",\n  \"efficientnetv2-l-21k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_l/feature_vector/2\",\n  \"efficientnetv2-xl-21k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_xl/feature_vector/2\",\n  \"efficientnetv2-b0-21k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_b0/feature_vector/2\",\n  \"efficientnetv2-b1-21k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_b1/feature_vector/2\",\n  \"efficientnetv2-b2-21k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_b2/feature_vector/2\",\n  \"efficientnetv2-b3-21k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_b3/feature_vector/2\",\n  \"efficientnetv2-s-21k-ft1k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_ft1k_s/feature_vector/2\",\n  \"efficientnetv2-m-21k-ft1k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_ft1k_m/feature_vector/2\",\n  \"efficientnetv2-l-21k-ft1k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_ft1k_l/feature_vector/2\",\n  \"efficientnetv2-xl-21k-ft1k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_ft1k_xl/feature_vector/2\",\n  \"efficientnetv2-b0-21k-ft1k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_ft1k_b0/feature_vector/2\",\n  \"efficientnetv2-b1-21k-ft1k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_ft1k_b1/feature_vector/2\",\n  \"efficientnetv2-b2-21k-ft1k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_ft1k_b2/feature_vector/2\",\n  \"efficientnetv2-b3-21k-ft1k\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet21k_ft1k_b3/feature_vector/2\",\n  \"efficientnetv2-b0\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet1k_b0/feature_vector/2\",\n  \"efficientnetv2-b1\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet1k_b1/feature_vector/2\",\n  \"efficientnetv2-b2\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet1k_b2/feature_vector/2\",\n  \"efficientnetv2-b3\": \"https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet1k_b3/feature_vector/2\",\n  \"efficientnet_b0\": \"https://tfhub.dev/tensorflow/efficientnet/b0/feature-vector/1\",\n  \"efficientnet_b1\": \"https://tfhub.dev/tensorflow/efficientnet/b1/feature-vector/1\",\n  \"efficientnet_b2\": \"https://tfhub.dev/tensorflow/efficientnet/b2/feature-vector/1\",\n  \"efficientnet_b3\": \"https://tfhub.dev/tensorflow/efficientnet/b3/feature-vector/1\",\n  \"efficientnet_b4\": \"https://tfhub.dev/tensorflow/efficientnet/b4/feature-vector/1\",\n  \"efficientnet_b5\": \"https://tfhub.dev/tensorflow/efficientnet/b5/feature-vector/1\",\n  \"efficientnet_b6\": \"https://tfhub.dev/tensorflow/efficientnet/b6/feature-vector/1\",\n  \"efficientnet_b7\": \"https://tfhub.dev/tensorflow/efficientnet/b7/feature-vector/1\",\n  \"bit_s-r50x1\": \"https://tfhub.dev/google/bit/s-r50x1/1\",\n  \"inception_v3\": \"https://tfhub.dev/google/imagenet/inception_v3/feature-vector/4\",\n  \"inception_resnet_v2\": \"https://tfhub.dev/google/imagenet/inception_resnet_v2/feature-vector/4\",\n  \"resnet_v1_50\": \"https://tfhub.dev/google/imagenet/resnet_v1_50/feature-vector/4\",\n  \"resnet_v1_101\": \"https://tfhub.dev/google/imagenet/resnet_v1_101/feature-vector/4\",\n  \"resnet_v1_152\": \"https://tfhub.dev/google/imagenet/resnet_v1_152/feature-vector/4\",\n  \"resnet_v2_50\": \"https://tfhub.dev/google/imagenet/resnet_v2_50/feature-vector/4\",\n  \"resnet_v2_101\": \"https://tfhub.dev/google/imagenet/resnet_v2_101/feature-vector/4\",\n  \"resnet_v2_152\": \"https://tfhub.dev/google/imagenet/resnet_v2_152/feature-vector/4\",\n  \"nasnet_large\": \"https://tfhub.dev/google/imagenet/nasnet_large/feature_vector/4\",\n  \"nasnet_mobile\": \"https://tfhub.dev/google/imagenet/nasnet_mobile/feature_vector/4\",\n  \"pnasnet_large\": \"https://tfhub.dev/google/imagenet/pnasnet_large/feature_vector/4\",\n  \"mobilenet_v2_100_224\": \"https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/4\",\n  \"mobilenet_v2_130_224\": \"https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/feature_vector/4\",\n  \"mobilenet_v2_140_224\": \"https://tfhub.dev/google/imagenet/mobilenet_v2_140_224/feature_vector/4\",\n  \"mobilenet_v3_small_100_224\": \"https://tfhub.dev/google/imagenet/mobilenet_v3_small_100_224/feature_vector/5\",\n  \"mobilenet_v3_small_075_224\": \"https://tfhub.dev/google/imagenet/mobilenet_v3_small_075_224/feature_vector/5\",\n  \"mobilenet_v3_large_100_224\": \"https://tfhub.dev/google/imagenet/mobilenet_v3_large_100_224/feature_vector/5\",\n  \"mobilenet_v3_large_075_224\": \"https://tfhub.dev/google/imagenet/mobilenet_v3_large_075_224/feature_vector/5\",\n}\n\nmodel_image_size_map = {\n  \"efficientnetv2-s\": 384,\n  \"efficientnetv2-m\": 480,\n  \"efficientnetv2-l\": 480,\n  \"efficientnetv2-b0\": 224,\n  \"efficientnetv2-b1\": 240,\n  \"efficientnetv2-b2\": 260,\n  \"efficientnetv2-b3\": 300,\n  \"efficientnetv2-s-21k\": 384,\n  \"efficientnetv2-m-21k\": 480,\n  \"efficientnetv2-l-21k\": 480,\n  \"efficientnetv2-xl-21k\": 512,\n  \"efficientnetv2-b0-21k\": 224,\n  \"efficientnetv2-b1-21k\": 240,\n  \"efficientnetv2-b2-21k\": 260,\n  \"efficientnetv2-b3-21k\": 300,\n  \"efficientnetv2-s-21k-ft1k\": 384,\n  \"efficientnetv2-m-21k-ft1k\": 480,\n  \"efficientnetv2-l-21k-ft1k\": 480,\n  \"efficientnetv2-xl-21k-ft1k\": 512,\n  \"efficientnetv2-b0-21k-ft1k\": 224,\n  \"efficientnetv2-b1-21k-ft1k\": 240,\n  \"efficientnetv2-b2-21k-ft1k\": 260,\n  \"efficientnetv2-b3-21k-ft1k\": 300, \n  \"efficientnet_b0\": 224,\n  \"efficientnet_b1\": 240,\n  \"efficientnet_b2\": 260,\n  \"efficientnet_b3\": 300,\n  \"efficientnet_b4\": 380,\n  \"efficientnet_b5\": 456,\n  \"efficientnet_b6\": 528,\n  \"efficientnet_b7\": 600,\n  \"inception_v3\": 299,\n  \"inception_resnet_v2\": 299,\n  \"nasnet_large\": 331,\n  \"pnasnet_large\": 331,\n}\n","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2021-09-07T07:04:01.965875Z","iopub.execute_input":"2021-09-07T07:04:01.966223Z","iopub.status.idle":"2021-09-07T07:04:01.977944Z","shell.execute_reply.started":"2021-09-07T07:04:01.966181Z","shell.execute_reply":"2021-09-07T07:04:01.976930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model_name = \"efficientnetv2-xl-21k\"\n# model_handle = model_handle_map.get(model_name)\n# pixels = model_image_size_map.get(model_name, 224)\n\n# print(f\"Selected model: {model_name} : {model_handle}\")\n\n# IMAGE_SIZE = (pixels, pixels)\n# print(f\"Input size {IMAGE_SIZE}\")\n\n# BATCH_SIZE =  16","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:04:02.794321Z","iopub.execute_input":"2021-09-07T07:04:02.794677Z","iopub.status.idle":"2021-09-07T07:04:02.798584Z","shell.execute_reply.started":"2021-09-07T07:04:02.794647Z","shell.execute_reply":"2021-09-07T07:04:02.797331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create model\nmodel_handle = 'https://tfhub.dev/google/imagenet/efficientnet_v2_imagenet1k_s/classification/2'\nIMG_SIZE = (384,384)\nBATCH_SIZE = 16\nFINE_TUNING = False","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:04:03.106970Z","iopub.execute_input":"2021-09-07T07:04:03.107316Z","iopub.status.idle":"2021-09-07T07:04:03.113779Z","shell.execute_reply.started":"2021-09-07T07:04:03.107286Z","shell.execute_reply":"2021-09-07T07:04:03.112910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Creating the model\nmodel = tf.keras.Sequential([\n    tf.keras.layers.InputLayer(input_shape = IMG_SIZE+(3,)),\n    hub.KerasLayer(model_handle,trainable = FINE_TUNING),\n    Dropout(rate = 0.2),\n    Dense(oh_labels.shape[1])\n])\nmodel.build((None,)+IMG_SIZE+(3,))\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:17:11.015841Z","iopub.execute_input":"2021-09-07T07:17:11.016153Z","iopub.status.idle":"2021-09-07T07:17:21.282035Z","shell.execute_reply.started":"2021-09-07T07:17:11.016122Z","shell.execute_reply":"2021-09-07T07:17:21.281225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"optim = tf.keras.optimizers.SGD(learning_rate=0.001,momentum=0.9)\nloss = tf.keras.losses.BinaryCrossentropy(from_logits=True)\nmetrics = ['accuracy']\nmodel.compile(optimizer = optim,loss = loss,metrics = metrics)","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:17:23.813250Z","iopub.execute_input":"2021-09-07T07:17:23.813589Z","iopub.status.idle":"2021-09-07T07:17:23.828798Z","shell.execute_reply.started":"2021-09-07T07:17:23.813561Z","shell.execute_reply":"2021-09-07T07:17:23.827973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Preaparing data\nfrom tensorflow.keras.preprocessing.image import ImageDataGenerator","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:17:24.769490Z","iopub.execute_input":"2021-09-07T07:17:24.769823Z","iopub.status.idle":"2021-09-07T07:17:24.776242Z","shell.execute_reply.started":"2021-09-07T07:17:24.769795Z","shell.execute_reply":"2021-09-07T07:17:24.775296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def build_dataset_df(df,data_dir,x_col,y_col,batch_size):\n    datagen = ImageDataGenerator(rescale = 1./255,\n                                 horizontal_flip=True,\n                                 vertical_flip=True,\n                                 fill_mode = 'nearest',\n                                validation_split = 0.2)\n    \n    train_ds = datagen.flow_from_dataframe(\n        df,\n        directory=data_dir,\n        x_col=x_col,\n        y_col=y_col,\n        target_size=IMG_SIZE,\n        batch_size=batch_size,\n        class_mode='raw',\n        subset = 'training',\n        shuffle = True,\n        seed = 42\n    )\n    \n    val_ds = datagen.flow_from_dataframe(\n        df,\n        directory=data_dir,\n        x_col=x_col,\n        y_col=y_col,\n        target_size=IMG_SIZE,\n        batch_size=batch_size,\n        class_mode='raw',\n        subset = 'validation',\n        shuffle = False,\n        seed = 42\n    )\n    \n    return train_ds,val_ds","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:17:25.208162Z","iopub.execute_input":"2021-09-07T07:17:25.208539Z","iopub.status.idle":"2021-09-07T07:17:25.219515Z","shell.execute_reply.started":"2021-09-07T07:17:25.208498Z","shell.execute_reply":"2021-09-07T07:17:25.218548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path = os.path.join(DATA_DIR,'train_images')\ntrain_ds,valid_ds = build_dataset_df(train_df,train_path,'image',label_vals,BATCH_SIZE)","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:17:26.024115Z","iopub.execute_input":"2021-09-07T07:17:26.024493Z","iopub.status.idle":"2021-09-07T07:17:34.487948Z","shell.execute_reply.started":"2021-09-07T07:17:26.024454Z","shell.execute_reply":"2021-09-07T07:17:34.487078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hist = model.fit(train_ds,epochs=3,validation_data = valid_ds)","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:32:26.775335Z","iopub.execute_input":"2021-09-07T07:32:26.775664Z","iopub.status.idle":"2021-09-07T09:44:05.205493Z","shell.execute_reply.started":"2021-09-07T07:32:26.775634Z","shell.execute_reply":"2021-09-07T09:44:05.202770Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img,lab = train_ds.next()\nprint(img.shape,lab.shape)","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:06:37.130875Z","iopub.execute_input":"2021-09-07T07:06:37.131208Z","iopub.status.idle":"2021-09-07T07:06:39.427656Z","shell.execute_reply.started":"2021-09-07T07:06:37.131175Z","shell.execute_reply":"2021-09-07T07:06:39.426739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res = model.predict(img)","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:07:36.851718Z","iopub.execute_input":"2021-09-07T07:07:36.852051Z","iopub.status.idle":"2021-09-07T07:07:37.001511Z","shell.execute_reply.started":"2021-09-07T07:07:36.852020Z","shell.execute_reply":"2021-09-07T07:07:37.000376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res.shape","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:07:43.270079Z","iopub.execute_input":"2021-09-07T07:07:43.270437Z","iopub.status.idle":"2021-09-07T07:07:43.277374Z","shell.execute_reply.started":"2021-09-07T07:07:43.270404Z","shell.execute_reply":"2021-09-07T07:07:43.276294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def sigmoid(x):\n    return 1./(1 + np.exp(-x))","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:08:51.209989Z","iopub.execute_input":"2021-09-07T07:08:51.210345Z","iopub.status.idle":"2021-09-07T07:08:51.214377Z","shell.execute_reply.started":"2021-09-07T07:08:51.210312Z","shell.execute_reply":"2021-09-07T07:08:51.213298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sigmoid(res[0])","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:32:18.281416Z","iopub.execute_input":"2021-09-07T07:32:18.281752Z","iopub.status.idle":"2021-09-07T07:32:18.288181Z","shell.execute_reply.started":"2021-09-07T07:32:18.281723Z","shell.execute_reply":"2021-09-07T07:32:18.287109Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lab[0]","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:07:56.360666Z","iopub.execute_input":"2021-09-07T07:07:56.361016Z","iopub.status.idle":"2021-09-07T07:07:56.366920Z","shell.execute_reply.started":"2021-09-07T07:07:56.360982Z","shell.execute_reply":"2021-09-07T07:07:56.365975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.losses import BinaryCrossentropy,CategoricalCrossentropy","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:14:14.889986Z","iopub.execute_input":"2021-09-07T07:14:14.890318Z","iopub.status.idle":"2021-09-07T07:14:14.894585Z","shell.execute_reply.started":"2021-09-07T07:14:14.890286Z","shell.execute_reply":"2021-09-07T07:14:14.893554Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bce = BinaryCrossentropy(from_logits = True)\ncate = CategoricalCrossentropy(from_logits = True)","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:15:22.033921Z","iopub.execute_input":"2021-09-07T07:15:22.034263Z","iopub.status.idle":"2021-09-07T07:15:22.037882Z","shell.execute_reply.started":"2021-09-07T07:15:22.034227Z","shell.execute_reply":"2021-09-07T07:15:22.037085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bce(res,lab).numpy()","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:15:46.989739Z","iopub.execute_input":"2021-09-07T07:15:46.990145Z","iopub.status.idle":"2021-09-07T07:15:46.999643Z","shell.execute_reply.started":"2021-09-07T07:15:46.990112Z","shell.execute_reply":"2021-09-07T07:15:46.998505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cate(res,lab).numpy()","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:15:57.008044Z","iopub.execute_input":"2021-09-07T07:15:57.008441Z","iopub.status.idle":"2021-09-07T07:15:57.021451Z","shell.execute_reply.started":"2021-09-07T07:15:57.008406Z","shell.execute_reply":"2021-09-07T07:15:57.020314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"res[0],lab[0]","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:16:14.413399Z","iopub.execute_input":"2021-09-07T07:16:14.413819Z","iopub.status.idle":"2021-09-07T07:16:14.428271Z","shell.execute_reply.started":"2021-09-07T07:16:14.413784Z","shell.execute_reply":"2021-09-07T07:16:14.427341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"?BinaryCrossentropy","metadata":{"execution":{"iopub.status.busy":"2021-09-07T07:16:26.517027Z","iopub.execute_input":"2021-09-07T07:16:26.517412Z","iopub.status.idle":"2021-09-07T07:16:26.526036Z","shell.execute_reply.started":"2021-09-07T07:16:26.517368Z","shell.execute_reply":"2021-09-07T07:16:26.524933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}