{"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 cv2\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-04-06T19:53:55.527987Z","iopub.execute_input":"2022-04-06T19:53:55.528319Z","iopub.status.idle":"2022-04-06T19:53:55.532883Z","shell.execute_reply.started":"2022-04-06T19:53:55.528272Z","shell.execute_reply":"2022-04-06T19:53:55.531936Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BASE_DIR = \"../input/sorghum-id-fgvc-9/train_images\"\ndf_train = pd.read_csv(\"../input/sorghum-id-fgvc-9/train_cultivar_mapping.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:57:11.267617Z","iopub.execute_input":"2022-04-06T19:57:11.268014Z","iopub.status.idle":"2022-04-06T19:57:11.300360Z","shell.execute_reply.started":"2022-04-06T19:57:11.267970Z","shell.execute_reply":"2022-04-06T19:57:11.299226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(8, 25))\nsns.countplot(y=\"cultivar\", data=df_train,);","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:57:14.798222Z","iopub.execute_input":"2022-04-06T19:57:14.798485Z","iopub.status.idle":"2022-04-06T19:57:16.531675Z","shell.execute_reply.started":"2022-04-06T19:57:14.798457Z","shell.execute_reply":"2022-04-06T19:57:16.530717Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2><center>Just a visualization<center><h2/>","metadata":{}},{"cell_type":"code","source":"def visualize_batch(image_ids, labels):\n    plt.figure(figsize=(16, 12))\n    \n    for ind, (image_id, label) in enumerate(zip(image_ids, labels)):\n        plt.subplot(4, 4, ind + 1)\n        image = cv2.imread(os.path.join(BASE_DIR, image_id))\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)\n\n        plt.imshow(image)\n        plt.title(f\"Class: {label}\", fontsize=12)\n        plt.axis(\"off\")\n    \n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:57:19.909994Z","iopub.execute_input":"2022-04-06T19:57:19.910273Z","iopub.status.idle":"2022-04-06T19:57:19.917125Z","shell.execute_reply.started":"2022-04-06T19:57:19.910244Z","shell.execute_reply":"2022-04-06T19:57:19.916020Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tmp_df = df_train.sample(12)\nimage_ids = tmp_df[\"image\"].values\nlabels = tmp_df[\"cultivar\"].values\n\nvisualize_batch(image_ids, labels)","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:57:20.612847Z","iopub.execute_input":"2022-04-06T19:57:20.613162Z","iopub.status.idle":"2022-04-06T19:57:23.453920Z","shell.execute_reply.started":"2022-04-06T19:57:20.613132Z","shell.execute_reply":"2022-04-06T19:57:23.452995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label = df_train.cultivar.dropna().unique()\nfor i in label:\n    \n    tmp_df = df_train[df_train[\"cultivar\"] == str(i)]\n    print(f\"Total train images for class {i}: {tmp_df.shape[0]}\")\n\n    tmp_df = tmp_df.sample(4)\n    image_ids = tmp_df[\"image\"].values\n    labels = tmp_df[\"cultivar\"].values\n\n    visualize_batch(image_ids, labels)","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:57:23.455924Z","iopub.execute_input":"2022-04-06T19:57:23.456281Z","iopub.status.idle":"2022-04-06T19:58:54.184288Z","shell.execute_reply.started":"2022-04-06T19:57:23.456232Z","shell.execute_reply":"2022-04-06T19:58:54.183377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# WORK IN PROGRESS...","metadata":{}}]}