{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceType":"competition","sourceId":24800,"datasetId":1042002,"databundleVersionId":1831594},{"sourceType":"datasetVersion","sourceId":9355809,"datasetId":5671733,"databundleVersionId":9554368},{"sourceType":"datasetVersion","sourceId":1810938,"datasetId":1075803,"databundleVersionId":1848422}],"dockerImageVersionId":30683,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"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\n# for 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":"2024-09-10T02:24:26.151117Z","iopub.execute_input":"2024-09-10T02:24:26.151451Z","iopub.status.idle":"2024-09-10T02:24:27.207879Z","shell.execute_reply.started":"2024-09-10T02:24:26.151426Z","shell.execute_reply":"2024-09-10T02:24:27.207105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Display generic output messages\n!pip install colorama\n\n# Library for visualizing bounding boxes\n!pip install bbox-visualizer\n\n# Install ONNX library, will be used to convert from pytorch model to a tf model\n!pip install onnx onnxruntime onnxsim onnx-tf","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:24:27.209485Z","iopub.execute_input":"2024-09-10T02:24:27.209848Z","iopub.status.idle":"2024-09-10T02:25:08.938982Z","shell.execute_reply.started":"2024-09-10T02:24:27.209825Z","shell.execute_reply":"2024-09-10T02:25:08.938027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import bbox_visualizer as bbv\nimport cv2\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport shutil, os\nimport tensorflow as tf\nimport yaml\n\nfrom colorama import Fore, Back, Style\nfrom IPython.display import Image, display, clear_output\nfrom sklearn.model_selection import GroupShuffleSplit \nfrom tqdm.notebook import tqdm\nfrom typing import List","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:25:08.94042Z","iopub.execute_input":"2024-09-10T02:25:08.94072Z","iopub.status.idle":"2024-09-10T02:25:24.050925Z","shell.execute_reply.started":"2024-09-10T02:25:08.940691Z","shell.execute_reply":"2024-09-10T02:25:24.050155Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !rm -rf /kaggle/working/data\n!mkdir -p /kaggle/working/data","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:25:24.051976Z","iopub.execute_input":"2024-09-10T02:25:24.052519Z","iopub.status.idle":"2024-09-10T02:25:25.082869Z","shell.execute_reply.started":"2024-09-10T02:25:24.052493Z","shell.execute_reply":"2024-09-10T02:25:25.08157Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cp -r /kaggle/input/vinbigdata-chest-xray-resized-png-1024x1024/* /kaggle/working/data/","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:25:25.085866Z","iopub.execute_input":"2024-09-10T02:25:25.086181Z","iopub.status.idle":"2024-09-10T02:29:04.563987Z","shell.execute_reply.started":"2024-09-10T02:25:25.086154Z","shell.execute_reply":"2024-09-10T02:29:04.562804Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cp /kaggle/input/vinbigdata-chest-xray-abnormalities-detection/train.csv /kaggle/working/data/","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:04.565499Z","iopub.execute_input":"2024-09-10T02:29:04.56582Z","iopub.status.idle":"2024-09-10T02:29:05.642048Z","shell.execute_reply.started":"2024-09-10T02:29:04.565792Z","shell.execute_reply":"2024-09-10T02:29:05.640979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cp /kaggle/input/lables/output.csv /kaggle/working/data/","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:05.643495Z","iopub.execute_input":"2024-09-10T02:29:05.643814Z","iopub.status.idle":"2024-09-10T02:29:06.676406Z","shell.execute_reply.started":"2024-09-10T02:29:05.643787Z","shell.execute_reply":"2024-09-10T02:29:06.675257Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Clone the YoloV9 repository, install the libray, and obtain the model\n!git clone https://github.com/WongKinYiu/yolov9.git\n!wget https://github.com/WongKinYiu/yolov9/releases/download/v0.1/yolov9-e.pt","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:06.677965Z","iopub.execute_input":"2024-09-10T02:29:06.678339Z","iopub.status.idle":"2024-09-10T02:29:10.526375Z","shell.execute_reply.started":"2024-09-10T02:29:06.678296Z","shell.execute_reply":"2024-09-10T02:29:10.525378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!wget https://github.com/WongKinYiu/yolov9/releases/download/v0.1/yolov9-c.pt","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:10.527783Z","iopub.execute_input":"2024-09-10T02:29:10.528073Z","iopub.status.idle":"2024-09-10T02:29:12.277663Z","shell.execute_reply.started":"2024-09-10T02:29:10.528048Z","shell.execute_reply":"2024-09-10T02:29:12.276519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!wget https://github.com/WongKinYiu/yolov9/releases/download/v0.1/gelan-c.pt","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:12.279258Z","iopub.execute_input":"2024-09-10T02:29:12.279673Z","iopub.status.idle":"2024-09-10T02:29:14.040223Z","shell.execute_reply.started":"2024-09-10T02:29:12.279634Z","shell.execute_reply":"2024-09-10T02:29:14.039253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -r /kaggle/working/yolov9/requirements.txt","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:14.041724Z","iopub.execute_input":"2024-09-10T02:29:14.042057Z","iopub.status.idle":"2024-09-10T02:29:27.571624Z","shell.execute_reply.started":"2024-09-10T02:29:14.042028Z","shell.execute_reply":"2024-09-10T02:29:27.570437Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"IMAGE_SIZE = 1024\nTRAIN_IMAGES_DIRECTORY = '/kaggle/working/data/train/'\nTEST_IMAGES_DIRECTORY = '/kaggle/working/data/test/'\n\nTRAIN_IMAGES_PATH_REFACTORED = '/kaggle/working/refactored_data/images/train/'\nTRAIN_LABELS_PATH_REFACTORED = '/kaggle/working/refactored_data/labels/train/'\nVALID_IMAGES_PATH_REFACTORED = '/kaggle/working/refactored_data/images/val/'\nVALID_LABELS_PATH_REFACTORED = '/kaggle/working/refactored_data/labels/val/'","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:27.573018Z","iopub.execute_input":"2024-09-10T02:29:27.573326Z","iopub.status.idle":"2024-09-10T02:29:27.579008Z","shell.execute_reply.started":"2024-09-10T02:29:27.573299Z","shell.execute_reply":"2024-09-10T02:29:27.578221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('data/output.csv')\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:27.580007Z","iopub.execute_input":"2024-09-10T02:29:27.580272Z","iopub.status.idle":"2024-09-10T02:29:28.346621Z","shell.execute_reply.started":"2024-09-10T02:29:27.580251Z","shell.execute_reply":"2024-09-10T02:29:28.345684Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_base_df = pd.read_csv('data/train.csv')\ntrain_base_df #image_id,class_name,class_id,rad_id,x_min,y_min,x_max,y_max,width,height","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:28.352933Z","iopub.execute_input":"2024-09-10T02:29:28.353245Z","iopub.status.idle":"2024-09-10T02:29:28.524227Z","shell.execute_reply.started":"2024-09-10T02:29:28.353218Z","shell.execute_reply":"2024-09-10T02:29:28.52332Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Tạo từ điển ánh xạ từ class_id đến class_name\nclass_id_to_name = dict(zip(train_base_df['class_id'], train_base_df['class_name']))\n\n# Thêm cột class_name vào new_df dựa trên class_id\ntrain_df['class_name'] = train_df['class_id'].map(class_id_to_name)\n\n# Kiểm tra new_df sau khi thêm cột\ntrain_df\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:28.525506Z","iopub.execute_input":"2024-09-10T02:29:28.525867Z","iopub.status.idle":"2024-09-10T02:29:28.566992Z","shell.execute_reply.started":"2024-09-10T02:29:28.525833Z","shell.execute_reply":"2024-09-10T02:29:28.566166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = 'data/train/'\nimg_path = []\nfor i in train_df['image_id']:\n  img_path.append(path+i+'.png')\n\ntrain_df['img_path'] = img_path\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:28.568063Z","iopub.execute_input":"2024-09-10T02:29:28.568325Z","iopub.status.idle":"2024-09-10T02:29:28.598448Z","shell.execute_reply.started":"2024-09-10T02:29:28.568293Z","shell.execute_reply":"2024-09-10T02:29:28.597412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#x_min, y_min, x_max, y_max normalization값으로 update\ntrain_df['x_min'] = train_df.apply(lambda row: (row.x_min) /1024, axis =1)\ntrain_df['y_min'] = train_df.apply(lambda row: (row.y_min) /1024, axis =1)\n\ntrain_df['x_max'] = train_df.apply(lambda row: (row.x_max) /1024, axis =1)\ntrain_df['y_max'] = train_df.apply(lambda row: (row.y_max) /1024, axis =1)\n#x_mid, y_mid가 추가\ntrain_df['x_mid'] = train_df.apply(lambda row: (row.x_min + row.x_max)/2,axis =1)\ntrain_df['y_mid'] = train_df.apply(lambda row: (row.y_min + row.y_max)/2, axis =1)\n#normalization된 width & height 추가\ntrain_df['w'] = train_df.apply(lambda row: (row.x_max - row.x_min), axis = 1)\ntrain_df['h'] = train_df.apply(lambda row: (row.y_max - row.y_min), axis = 1)\n#area 추가\ntrain_df['area'] = train_df['w']*train_df['h']\ntrain_df","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:28.59955Z","iopub.execute_input":"2024-09-10T02:29:28.599809Z","iopub.status.idle":"2024-09-10T02:29:32.248042Z","shell.execute_reply.started":"2024-09-10T02:29:28.599786Z","shell.execute_reply":"2024-09-10T02:29:32.24704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df['ori_x_min'] = (train_df['x_min']*1024).astype('int')\ntrain_df['ori_y_min'] = (train_df['y_min']*1024).astype('int')\ntrain_df['ori_x_max'] = (train_df['x_max']*1024).astype('int')\ntrain_df['ori_y_max'] = (train_df['y_max']*1024).astype('int')\n\ntrain_df['ori_x_mid'] = (train_df['x_mid']*1024).astype('int')\ntrain_df['ori_y_mid'] = (train_df['y_mid']*1024).astype('int')\ntrain_df['ori_w'] = (train_df['w']*1024).astype('int')\ntrain_df['ori_h'] = (train_df['h']*1024).astype('int')","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:32.249196Z","iopub.execute_input":"2024-09-10T02:29:32.249512Z","iopub.status.idle":"2024-09-10T02:29:32.264457Z","shell.execute_reply.started":"2024-09-10T02:29:32.249486Z","shell.execute_reply":"2024-09-10T02:29:32.263548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_df = train_df.copy()\nfinal_df = final_df[['image_id', 'class_name', 'class_id', 'ori_x_min', 'ori_y_min', 'ori_x_max', 'ori_y_max', 'ori_x_mid', 'ori_y_mid', 'ori_w', 'ori_h','img_path']]\nfinal_df","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:32.265554Z","iopub.execute_input":"2024-09-10T02:29:32.265836Z","iopub.status.idle":"2024-09-10T02:29:32.301729Z","shell.execute_reply.started":"2024-09-10T02:29:32.265812Z","shell.execute_reply":"2024-09-10T02:29:32.300745Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport cv2\nimport numpy as np\nfrom tqdm import tqdm\nimport os\n\n# Đọc dữ liệu từ final_df (giả sử final_df đã được định nghĩa trước đó)\nfiltered_df = final_df[final_df['class_id'].isin([1, 12])].copy()\n\n# Hàm để cập nhật bounding box sau khi tăng cường\ndef update_bounding_box(bbox, transform_matrix):\n    \"\"\"\n    Cập nhật bounding box sau khi áp dụng ma trận biến đổi.\n    \n    Args:\n        bbox (list): Danh sách chứa các tọa độ bounding box [x_min, y_min, x_max, y_max].\n        transform_matrix (np.array): Ma trận biến đổi affine 2x3.\n    \n    Returns:\n        tuple: Tọa độ bounding box mới [x_min, y_min, x_max, y_max].\n    \"\"\"\n    ori_x_min, ori_y_min, ori_x_max, ori_y_max = bbox\n    \n    # Tạo mảng các điểm của bounding box\n    points = np.array([\n        [ori_x_min, ori_y_min],  # Góc trên bên trái\n        [ori_x_max, ori_y_min],  # Góc trên bên phải\n        [ori_x_max, ori_y_max],  # Góc dưới bên phải\n        [ori_x_min, ori_y_max]   # Góc dưới bên trái\n    ])\n    \n    # Chuyển đổi điểm bằng ma trận biến đổi\n    # Thay đổi transform_matrix thành dạng 3x3 để dễ tính toán\n    # Thêm hàng thứ ba [0, 0, 1] vào ma trận biến đổi để phù hợp với tọa độ đồng nhất\n    transform_matrix_3x3 = np.vstack([transform_matrix, [0, 0, 1]])\n    \n    # Thêm hàng thứ ba [1] vào các điểm để phù hợp với tọa độ đồng nhất\n    points_homogeneous = np.hstack([points, np.ones((points.shape[0], 1))])\n    \n    # Áp dụng ma trận biến đổi\n    transformed_points = np.dot(points_homogeneous, transform_matrix_3x3.T)\n    \n    # Chuyển đổi trở lại tọa độ không đồng nhất\n    transformed_points[:, 0] /= transformed_points[:, 2]\n    transformed_points[:, 1] /= transformed_points[:, 2]\n    \n    # Tìm giá trị min và max cho các trục x và y\n    ori_x_min = transformed_points[:, 0].min()\n    ori_y_min = transformed_points[:, 1].min()\n    ori_x_max = transformed_points[:, 0].max()\n    ori_y_max = transformed_points[:, 1].max()\n    \n    return ori_x_min, ori_y_min, ori_x_max, ori_y_max\n\n# Thực hiện tăng cường dữ liệu và lưu thông số mới vào CSV\nnew_rows = []\n\nfor index, row in tqdm(filtered_df.iterrows(), total=filtered_df.shape[0]):\n    image_path = row['img_path']\n    bbox = [row['ori_x_min'], row['ori_y_min'], row['ori_x_max'], row['ori_y_max']]\n    image_id = row['image_id']\n    class_name = row['class_name']\n    class_id = row['class_id']\n    ori_x_mid = row['ori_x_mid']\n    ori_y_mid = row['ori_y_mid']\n    ori_w = row['ori_w']\n    ori_h = row['ori_h']\n    \n    # Đọc ảnh\n    image = cv2.imread(image_path)\n    if image is None:\n        continue\n    \n    # Ví dụ về một biến đổi: xoay ảnh 90 độ\n    height, width = image.shape[:2]\n    M = cv2.getRotationMatrix2D((width / 2, height / 2), 90, 1)\n    rotated_image = cv2.warpAffine(image, M, (width, height))\n    \n    # Cập nhật bounding box\n    new_bbox = update_bounding_box(bbox, M)\n    \n    # Lưu ảnh mới\n    new_image_path = os.path.splitext(image_path)[0] + '_rotated.png'\n    cv2.imwrite(new_image_path, rotated_image)\n    \n    # Tạo một dòng mới với thông số cập nhật\n    new_row = row.copy()\n    new_row['img_path'] = new_image_path\n    new_row['ori_x_min'], new_row['ori_y_min'], new_row['ori_x_max'], new_row['ori_y_max'] = new_bbox\n    new_row['image_id'] = image_id + '_rotated'\n    new_row['class_name'] = class_name\n    new_row['class_id'] = class_id\n    new_row['ori_x_mid'] = ori_x_mid\n    new_row['ori_y_mid'] = ori_y_mid\n    new_row['ori_w'] = ori_w\n    new_row['ori_h'] = ori_h\n    new_rows.append(new_row)\n\n# Tạo DataFrame từ các dòng mới\nnew5_df = pd.DataFrame(new_rows)\n\n# # Gộp dữ liệu mới vào DataFrame gốc\n# augmented_df = pd.concat([final_df, new_df], ignore_index=True)\n\n# # Lưu DataFrame đã cập nhật vào file CSV mới\n# augmented_df.to_csv('/kaggle/working/data/train_augmented.csv', index=False)\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:32.303364Z","iopub.execute_input":"2024-09-10T02:29:32.303709Z","iopub.status.idle":"2024-09-10T02:29:58.102158Z","shell.execute_reply.started":"2024-09-10T02:29:32.303682Z","shell.execute_reply":"2024-09-10T02:29:58.101098Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def flip_image(image_path, bbox):\n    \"\"\"\n    Lật ảnh theo chiều ngang và cập nhật bounding box.\n\n    Args:\n        image_path (str): Đường dẫn đến ảnh gốc.\n        bbox (list): Danh sách chứa các tọa độ bounding box [x_min, y_min, x_max, y_max].\n\n    Returns:\n        tuple: Đường dẫn ảnh mới và bounding box đã được cập nhật.\n    \"\"\"\n    # Đọc ảnh gốc\n    image = cv2.imread(image_path)\n    if image is None:\n        return None, None\n\n    # Lật ảnh theo chiều ngang\n    flipped_image = cv2.flip(image, 1)\n\n    # Cập nhật bounding box\n    width = image.shape[1]\n    flipped_bbox = [\n        width - bbox[2], bbox[1],  # x_max -> new_x_min, y_min\n        width - bbox[0], bbox[3]   # x_min -> new_x_max, y_max\n    ]\n\n    # Lưu ảnh mới\n    new_image_path = os.path.splitext(image_path)[0] + '_flip.png'\n    cv2.imwrite(new_image_path, flipped_image)\n    \n    return new_image_path, flipped_bbox\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:58.103687Z","iopub.execute_input":"2024-09-10T02:29:58.10427Z","iopub.status.idle":"2024-09-10T02:29:58.112906Z","shell.execute_reply.started":"2024-09-10T02:29:58.104238Z","shell.execute_reply":"2024-09-10T02:29:58.111952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def flip_images_in_df(df):\n    \"\"\"\n    Lật ảnh cho các lớp cụ thể và cập nhật thông tin bounding box trong DataFrame.\n\n    Args:\n        df (pd.DataFrame): DataFrame chứa thông tin về ảnh và bounding box.\n\n    Returns:\n        pd.DataFrame: DataFrame đã được cập nhật với ảnh lật và bounding box mới.\n    \"\"\"\n    filtered_df = final_df[final_df['class_id'].isin([1, 12,2,4])].copy()\n    new_rows = []\n\n    for index, row in tqdm(df.iterrows(), total=df.shape[0]):\n        image_path = row['img_path']\n        bbox = [row['ori_x_min'], row['ori_y_min'], row['ori_x_max'], row['ori_y_max']]\n        image_id = row['image_id']\n        class_name = row['class_name']\n        class_id = row['class_id']\n        ori_x_mid = row['ori_x_mid']\n        ori_y_mid = row['ori_y_mid']\n        ori_w = row['ori_w']\n        ori_h = row['ori_h']\n        \n        # Lật ảnh và cập nhật bounding box\n        new_image_path, new_bbox = flip_image(image_path, bbox)\n        \n        if new_image_path is None:\n            continue\n        \n        # Tạo một dòng mới với thông số cập nhật\n        new_row = row.copy()\n        new_row['img_path'] = new_image_path\n        new_row['ori_x_min'], new_row['ori_y_min'], new_row['ori_x_max'], new_row['ori_y_max'] = new_bbox\n        new_row['image_id'] = image_id + '_flip'\n        new_row['class_name'] = class_name\n        new_row['class_id'] = class_id\n        new_row['ori_x_mid'] = ori_x_mid\n        new_row['ori_y_mid'] = ori_y_mid\n        new_row['ori_w'] = ori_w\n        new_row['ori_h'] = ori_h\n        new_rows.append(new_row)\n\n    # Tạo DataFrame từ các dòng mới\n    new_df = pd.DataFrame(new_rows)\n\n    return new_df\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:58.113955Z","iopub.execute_input":"2024-09-10T02:29:58.114273Z","iopub.status.idle":"2024-09-10T02:29:58.131274Z","shell.execute_reply.started":"2024-09-10T02:29:58.114238Z","shell.execute_reply":"2024-09-10T02:29:58.130277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new5_df","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:58.132393Z","iopub.execute_input":"2024-09-10T02:29:58.132714Z","iopub.status.idle":"2024-09-10T02:29:58.166492Z","shell.execute_reply.started":"2024-09-10T02:29:58.132686Z","shell.execute_reply":"2024-09-10T02:29:58.165424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filtered_df = final_df[final_df['class_id'].isin([1, 12])].copy()\nnew1_df = flip_images_in_df(filtered_df)","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:29:58.167845Z","iopub.execute_input":"2024-09-10T02:29:58.168174Z","iopub.status.idle":"2024-09-10T02:30:20.989318Z","shell.execute_reply.started":"2024-09-10T02:29:58.168147Z","shell.execute_reply":"2024-09-10T02:30:20.988446Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport cv2\nimport numpy as np\nimport imgaug.augmenters as iaa\nfrom tqdm import tqdm\nimport os\n\ndef zoom_image(image_path, bbox, zoom_factor):\n    \"\"\"\n    Zoom ảnh và cập nhật bounding box.\n\n    Args:\n        image_path (str): Đường dẫn đến ảnh gốc.\n        bbox (list): Danh sách chứa các tọa độ bounding box [x_min, y_min, x_max, y_max].\n        zoom_factor (float): Hệ số zoom.\n\n    Returns:\n        tuple: Đường dẫn ảnh mới và bounding box đã được cập nhật.\n    \"\"\"\n    # Đọc ảnh gốc\n    image = cv2.imread(image_path)\n    if image is None:\n        return None, None\n\n    # Tăng cường zoom\n    augment_img_zoom = iaa.Affine(scale=(zoom_factor))\n    zoomed_image = augment_img_zoom.augment_image(image)\n\n    # Cập nhật bounding box\n    height, width = image.shape[:2]\n    new_width, new_height = int(width * zoom_factor), int(height * zoom_factor)\n\n    # Tính toán offset để điều chỉnh bounding box\n    offset_x = (new_width - width) / 2\n    offset_y = (new_height - height) / 2\n\n    new_bbox = [\n        bbox[0] * zoom_factor - offset_x,  # x_min\n        bbox[1] * zoom_factor - offset_y,  # y_min\n        bbox[2] * zoom_factor - offset_x,  # x_max\n        bbox[3] * zoom_factor - offset_y   # y_max\n    ]\n\n    # Lưu ảnh mới\n    new_image_path = os.path.splitext(image_path)[0] + '_zoom.png'\n    cv2.imwrite(new_image_path, zoomed_image)\n    \n    return new_image_path, new_bbox\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:30:20.990491Z","iopub.execute_input":"2024-09-10T02:30:20.990749Z","iopub.status.idle":"2024-09-10T02:30:21.386471Z","shell.execute_reply.started":"2024-09-10T02:30:20.990727Z","shell.execute_reply":"2024-09-10T02:30:21.385673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def zoom_images_in_df(df, zoom_factor):\n    \"\"\"\n    Thực hiện zoom cho các ảnh thuộc lớp cụ thể và cập nhật thông tin bounding box trong DataFrame.\n\n    Args:\n        df (pd.DataFrame): DataFrame chứa thông tin về ảnh và bounding box.\n        zoom_factor (float): Hệ số zoom.\n\n    Returns:\n        pd.DataFrame: DataFrame đã được cập nhật với ảnh zoom và bounding box mới.\n    \"\"\"\n    new_rows = []\n\n    for index, row in tqdm(df.iterrows(), total=df.shape[0]):\n        image_path = row['img_path']\n        bbox = [row['ori_x_min'], row['ori_y_min'], row['ori_x_max'], row['ori_y_max']]\n        image_id = row['image_id']\n        class_name = row['class_name']\n        class_id = row['class_id']\n        ori_x_mid = row['ori_x_mid']\n        ori_y_mid = row['ori_y_mid']\n        ori_w = row['ori_w']\n        ori_h = row['ori_h']\n        \n        # Zoom ảnh và cập nhật bounding box\n        new_image_path, new_bbox = zoom_image(image_path, bbox, zoom_factor)\n        \n        if new_image_path is None:\n            continue\n        \n        # Tạo một dòng mới với thông số cập nhật\n        new_row = row.copy()\n        new_row['img_path'] = new_image_path\n        new_row['ori_x_min'], new_row['ori_y_min'], new_row['ori_x_max'], new_row['ori_y_max'] = new_bbox\n        new_row['image_id'] = image_id + '_zoom'\n        new_row['class_name'] = class_name\n        new_row['class_id'] = class_id\n        new_row['ori_x_mid'] = ori_x_mid\n        new_row['ori_y_mid'] = ori_y_mid\n        new_row['ori_w'] = ori_w\n        new_row['ori_h'] = ori_h\n        new_rows.append(new_row)\n\n    # Tạo DataFrame từ các dòng mới\n    new_df = pd.DataFrame(new_rows)\n\n    return new_df\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:30:21.38761Z","iopub.execute_input":"2024-09-10T02:30:21.388154Z","iopub.status.idle":"2024-09-10T02:30:21.397739Z","shell.execute_reply.started":"2024-09-10T02:30:21.388127Z","shell.execute_reply":"2024-09-10T02:30:21.396848Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"filtered_df = final_df[final_df['class_id'].isin([1, 12])].copy()\n\n# Áp dụng hàm zoom ảnh cho DataFrame đã lọc với hệ số zoom là 10% (1.1)\nnew3_df = zoom_images_in_df(filtered_df, zoom_factor=1.1)","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:30:21.398933Z","iopub.execute_input":"2024-09-10T02:30:21.399406Z","iopub.status.idle":"2024-09-10T02:30:45.763944Z","shell.execute_reply.started":"2024-09-10T02:30:21.399363Z","shell.execute_reply":"2024-09-10T02:30:45.762948Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport os\n\ndef clahe_image(image_list):\n    \"\"\"\n    Áp dụng CLAHE cho ảnh và lưu ảnh đã được tăng cường.\n\n    Args:\n        image_list (list): Danh sách các đường dẫn đến các ảnh cần áp dụng CLAHE.\n    \"\"\"\n    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))\n    \n    for path in image_list:\n        img = cv2.imread(path, cv2.IMREAD_GRAYSCALE)\n        if img is None:\n            continue\n        clahe_img = clahe.apply(img)\n        img_name = os.path.basename(path).split('.')[0]\n        new_image_path = f'{os.path.splitext(path)[0]}_clahe.png'\n        cv2.imwrite(new_image_path, clahe_img)\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:30:45.765404Z","iopub.execute_input":"2024-09-10T02:30:45.766139Z","iopub.status.idle":"2024-09-10T02:30:45.772502Z","shell.execute_reply.started":"2024-09-10T02:30:45.7661Z","shell.execute_reply":"2024-09-10T02:30:45.771439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nfrom tqdm import tqdm\n\n# Lọc DataFrame chỉ chứa các lớp có class_id là 1 và 12\nfiltered_df = final_df[final_df['class_id'].isin([1, 12,4])].copy()\n\n# Tạo danh sách các đường dẫn ảnh\nimage_list = filtered_df['img_path'].tolist()\n\n# Thực hiện CLAHE cho các ảnh\nclahe_image(image_list)\n\n# Cập nhật DataFrame với ảnh mới đã áp dụng CLAHE\ndef update_df_with_clahe(df):\n    new_rows = []\n\n    for index, row in tqdm(df.iterrows(), total=df.shape[0]):\n        image_path = row['img_path']\n        img_name = os.path.basename(image_path).split('.')[0]\n        new_image_path = f'{os.path.splitext(image_path)[0]}_clahe.png'\n\n        # Tạo một dòng mới với đường dẫn ảnh CLAHE\n        new_row = row.copy()\n        new_row['img_path'] = new_image_path\n        new_row['image_id'] = row['image_id'] + '_clahe'\n        new_rows.append(new_row)\n\n    # Tạo DataFrame từ các dòng mới\n    new_df = pd.DataFrame(new_rows)\n    \n    return new_df\n\n# Áp dụng hàm cập nhật DataFrame\nnew4_df = update_df_with_clahe(filtered_df)\n\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:30:45.773769Z","iopub.execute_input":"2024-09-10T02:30:45.774113Z","iopub.status.idle":"2024-09-10T02:31:13.200943Z","shell.execute_reply.started":"2024-09-10T02:30:45.774082Z","shell.execute_reply":"2024-09-10T02:31:13.200018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport os\n\ndef equ_image(image_list):\n    \"\"\"\n    Áp dụng EqualizeHist cho ảnh và lưu ảnh đã được tăng cường.\n\n    Args:\n        image_list (list): Danh sách các đường dẫn đến các ảnh cần áp dụng EqualizeHist.\n    \"\"\"\n    for path in image_list:\n        img = cv2.imread(path, cv2.IMREAD_GRAYSCALE)\n        if img is None:\n            continue\n        equ_img = cv2.equalizeHist(img)\n        img_name = os.path.basename(path).split('.')[0]\n        new_image_path = f'{os.path.splitext(path)[0]}_equ.png'\n        cv2.imwrite(new_image_path, equ_img)\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:31:13.202Z","iopub.execute_input":"2024-09-10T02:31:13.20385Z","iopub.status.idle":"2024-09-10T02:31:13.209385Z","shell.execute_reply.started":"2024-09-10T02:31:13.203823Z","shell.execute_reply":"2024-09-10T02:31:13.20855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nfrom tqdm import tqdm\n\n# Lọc DataFrame chỉ chứa các lớp có class_id là 1 và 12\nfiltered_df = final_df[final_df['class_id'].isin([1, 12,4,5,2,6])].copy()\n\n# Tạo danh sách các đường dẫn ảnh\nimage_list = filtered_df['img_path'].tolist()\n\n# Thực hiện EqualizeHist cho các ảnh\nequ_image(image_list)\n\n# Cập nhật DataFrame với ảnh mới đã áp dụng EqualizeHist\ndef update_df_with_equ(df):\n    new_rows = []\n\n    for index, row in tqdm(df.iterrows(), total=df.shape[0]):\n        image_path = row['img_path']\n        img_name = os.path.basename(image_path).split('.')[0]\n        new_image_path = f'{os.path.splitext(image_path)[0]}_equ.png'\n\n        # Tạo một dòng mới với đường dẫn ảnh EqualizeHist\n        new_row = row.copy()\n        new_row['img_path'] = new_image_path\n        new_row['image_id'] = row['image_id'] + '_equ'\n        new_rows.append(new_row)\n\n    # Tạo DataFrame từ các dòng mới\n    new_df = pd.DataFrame(new_rows)\n    \n    return new_df\n\n# Áp dụng hàm cập nhật DataFrame\n\n\n\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:31:13.210603Z","iopub.execute_input":"2024-09-10T02:31:13.210918Z","iopub.status.idle":"2024-09-10T02:32:57.53275Z","shell.execute_reply.started":"2024-09-10T02:31:13.210888Z","shell.execute_reply":"2024-09-10T02:32:57.531887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new2_df=update_df_with_equ(filtered_df)","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:32:57.534093Z","iopub.execute_input":"2024-09-10T02:32:57.534659Z","iopub.status.idle":"2024-09-10T02:32:58.319403Z","shell.execute_reply.started":"2024-09-10T02:32:57.534624Z","shell.execute_reply":"2024-09-10T02:32:58.318464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_train_df = pd.concat([new5_df, new1_df, new2_df, new4_df,new3_df, final_df], ignore_index=True)","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:32:58.32076Z","iopub.execute_input":"2024-09-10T02:32:58.32119Z","iopub.status.idle":"2024-09-10T02:32:58.328328Z","shell.execute_reply.started":"2024-09-10T02:32:58.321158Z","shell.execute_reply":"2024-09-10T02:32:58.327519Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_train_df","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:32:58.329435Z","iopub.execute_input":"2024-09-10T02:32:58.329979Z","iopub.status.idle":"2024-09-10T02:32:58.354286Z","shell.execute_reply.started":"2024-09-10T02:32:58.329954Z","shell.execute_reply":"2024-09-10T02:32:58.353353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n\n# Giả sử new_train_df đã tồn tại\n# Ví dụ:\n# new_train_df = pd.DataFrame(...)\n\n# Tạo một bản sao của new_train_df để xử lý\nnew_df = new_train_df.copy()\n\n# Đổi tên các cột liên quan\nnew_df.rename(columns={\n    'ori_x_min': 'x_min',\n    'ori_y_min': 'y_min',\n    'ori_x_max': 'x_max',\n    'ori_y_max': 'y_max'\n}, inplace=True)\n\n# Chuyển đổi giá trị các cột x_min, x_max, y_min, y_max\nnew_df['x_min'] = new_df['x_min'] / 1024\nnew_df['y_min'] = new_df['y_min'] / 1024\nnew_df['x_max'] = new_df['x_max'] / 1024\nnew_df['y_max'] = new_df['y_max'] / 1024\n\n# Chỉ giữ lại các cột x_min, x_max, y_min, y_max\nnew_df = new_df[['image_id','class_id','class_name','x_min', 'x_max', 'y_min', 'y_max']]\nnew_df['x_center'] = (new_df['x_max'] + new_df['x_min']) / 2\nnew_df['y_center'] = (new_df['y_max'] + new_df['y_min']) / 2\n\nnew_df['w'] = (new_df['x_max'] - new_df['x_min'])\nnew_df['h'] = (new_df['y_max'] - new_df['y_min'])\n# Hiển thị kết quả\nnew_df\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:32:58.355647Z","iopub.execute_input":"2024-09-10T02:32:58.3559Z","iopub.status.idle":"2024-09-10T02:32:58.387953Z","shell.execute_reply.started":"2024-09-10T02:32:58.355878Z","shell.execute_reply":"2024-09-10T02:32:58.387134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"new_df['class_id'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:32:58.389011Z","iopub.execute_input":"2024-09-10T02:32:58.389274Z","iopub.status.idle":"2024-09-10T02:32:58.398819Z","shell.execute_reply.started":"2024-09-10T02:32:58.389251Z","shell.execute_reply":"2024-09-10T02:32:58.397909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport numpy as np\nimport shutil\nimport yaml\nfrom sklearn.model_selection import GroupShuffleSplit\nfrom tqdm import tqdm\n\n# Training/validation splitting\nsplitter = GroupShuffleSplit(test_size=0.1)\nsplit = splitter.split(new_df, groups=new_df['image_id'])\ntrain_inds, valid_inds = next(split)\n\nvalid_df = new_df.iloc[valid_inds]\ntrain_df = new_df.iloc[train_inds]\n\n# Create images and labels directories for both training and validation\nfor folder in [\n    TRAIN_IMAGES_PATH_REFACTORED,\n    TRAIN_LABELS_PATH_REFACTORED,\n    VALID_IMAGES_PATH_REFACTORED,\n    VALID_LABELS_PATH_REFACTORED,\n]:\n    os.makedirs(folder, exist_ok=True)\n\n# Copy training images to its designated directory, and create a txt file for each image denoting its classes and their positions\nfor image in tqdm(train_df['image_id'].unique()):\n    records = train_df[train_df['image_id'] == image]\n    attributes = records[['class_id', 'x_center', 'y_center', 'w', 'h']].values\n    np.savetxt(\n        os.path.join(TRAIN_LABELS_PATH_REFACTORED, f'{image}.txt'),\n        attributes,\n        fmt=['%d', '%f', '%f', '%f', '%f']\n    )\n    shutil.copy(\n        os.path.join(TRAIN_IMAGES_DIRECTORY, f'{image}.png'),\n        TRAIN_IMAGES_PATH_REFACTORED\n    )\n\n# Copy validation images to its designated directory, and create a txt file for each image denoting its classes and their positions\nfor image in tqdm(valid_df['image_id'].unique()):\n    records = valid_df[valid_df['image_id'] == image]\n    attributes = records[['class_id', 'x_center', 'y_center', 'w', 'h']].values\n    np.savetxt(\n        os.path.join(VALID_LABELS_PATH_REFACTORED, f'{image}.txt'),\n        attributes,\n        fmt=['%d', '%f', '%f', '%f', '%f']\n    )\n    shutil.copy(\n        os.path.join(TRAIN_IMAGES_DIRECTORY, f'{image}.png'),\n        VALID_IMAGES_PATH_REFACTORED\n    )\n\n# Order the classes based on the class ID numerical value (in an ascending order)\nclass_ids, class_names = list(zip(*set(zip(new_df['class_id'], new_df['class_name']))))\nclasses = list(np.array(class_names)[np.argsort(class_ids)])\nclasses = list(map(lambda x: str(x), classes))\n\n# Store a list containing the path of each training image in a TXT file\nwith open('train.txt', 'w') as f:\n    for path in os.listdir(TRAIN_IMAGES_PATH_REFACTORED):\n        f.write(f'{TRAIN_IMAGES_PATH_REFACTORED}{path}\\n')\n\n# Store a list containing the path of each validation image in a TXT file\nwith open('valid.txt', 'w') as f:\n    for path in os.listdir(VALID_IMAGES_PATH_REFACTORED):\n        f.write(f'{VALID_IMAGES_PATH_REFACTORED}{path}\\n')\n\n# Create a dictionary containing the necessary configurations to run YOLO\ndata = dict(\n    train='train.txt',\n    val='valid.txt',\n    nc=14,  # Assuming 14 classes, adjust if needed\n    names=classes\n)\n\n# Store the configurations in a YAML file, to be absorbed later by YOLO\nwith open('yolo.yaml', 'w') as outfile:\n    yaml.dump(data, outfile, default_flow_style=False)\n\n# Return train dataframe and the original dataframe loaded from a CSV (assuming the CSV path is '/kaggle/working/data/train.csv')\n# return [pd.read_csv('/kaggle/working/data/train.csv'), train_df]\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:32:58.40014Z","iopub.execute_input":"2024-09-10T02:32:58.400445Z","iopub.status.idle":"2024-09-10T02:33:51.069374Z","shell.execute_reply.started":"2024-09-10T02:32:58.400374Z","shell.execute_reply":"2024-09-10T02:33:51.068298Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def train_model(\n        train_step: int = 1,  # Chọn lần huấn luyện (1 cho lần 1, 2 cho lần 2)\n        visualize: bool = False,\n        export_as_onnx: bool = False,\n        export_as_tf: bool = False,\n        export_as_tflite: bool = False,\n        conf_thres: float = 0.3,\n        iou_thres: float = 0.4,\n):\n\n\n    if train_step == 1:\n        # Train lần 1\n        print(\"Training lần 1...\")\n        !torchrun --nproc_per_node=2 --master_port 9527 /kaggle/working/yolov9/train_dual.py --device 0,1 --sync-bn --img {IMAGE_SIZE} --cfg /kaggle/working/yolov9/models/detect/yolov9-c.yaml --batch-size 8 --epochs 20 --data yolo.yaml --weights /kaggle/working/yolov9-c.pt --hyp /kaggle/working/yolov9/data/hyps/hyp.scratch-high.yaml --min-items 0 --close-mosaic 15\n\n        # Lưu trọng số sau lần train 1 vào /kaggle/outputs\n        print(\"Lưu mô hình sau lần 1...\")\n        !cp /kaggle/working/yolov9/runs/train/exp/weights/last.pt /kaggle/working/yolov9-c-lan1.pt\n\n        print(\"Đã hoàn thành lần huấn luyện 1. Lưu mô hình và dừng lại.\")\n\n        return  # Dừng lại ngay sau khi huấn luyện lần 1 hoàn thành\n\n    elif train_step == 2:\n        # Load mô hình từ lần train 1 và tiếp tục train lần 2\n        print(\"Training lần 2...\")\n        !torchrun --nproc_per_node=2 --master_port 9527 /kaggle/working/yolov9/train_dual.py --device 0,1 --sync-bn --img {IMAGE_SIZE} --cfg /kaggle/working/yolov9/models/detect/yolov9-c.yaml --batch-size 8 --epochs 20 --data yolo.yaml --resume /kaggle/outputs/yolov9-c-lan1.pt\n\n    if visualize:\n        # Visualize các kết quả sau lần huấn luyện\n        plt.rcParams.update({\n            'figure.figsize': (15, 8),\n            'axes.spines.left': False,\n            'axes.spines.right': False,\n            'axes.spines.bottom': False,\n            'axes.spines.top': False,\n            'xtick.bottom': False,\n            'xtick.labelbottom': False,\n            'ytick.labelleft': False,\n            'ytick.left': False,\n        })\n\n        for img_name in ['results.png', 'PR_curve.png', 'confusion_matrix.png']:\n            img_path = f'runs/train/exp/{img_name}'\n            plt.figure(figsize=(15, 8))\n            plt.imshow(plt.imread(img_path))\n            plt.title(f\"{img_name} (conf_thres={conf_thres}, iou_thres={iou_thres})\")\n            plt.axis('off')\n\n        plt.rcParams.update(plt.rcParamsDefault)\n        plt.rcParams.update({'figure.figsize': (15, 8)})\n\n    if export_as_onnx or export_as_tf or export_as_tflite:\n        print(\"Exporting mô hình...\")\n        !python yolov9/export.py --weights yolov9-c.pt --img-size {IMAGE_SIZE} {IMAGE_SIZE} --max-wh {IMAGE_SIZE} --grid --end2end --simplify\n\n        if export_as_tf or export_as_tflite:\n            !onnx-tf convert -i yolov9.onnx -o ./\n\n            if export_as_tflite:\n                converter = tf.lite.TFLiteConverter.from_saved_model('./')\n                tflite_model = converter.convert()\n                with open('yolov9.tflite', 'wb') as f:\n                    f.write(tflite_model)\n","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:33:51.071039Z","iopub.execute_input":"2024-09-10T02:33:51.071609Z","iopub.status.idle":"2024-09-10T02:33:51.119316Z","shell.execute_reply.started":"2024-09-10T02:33:51.07157Z","shell.execute_reply":"2024-09-10T02:33:51.118295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# raw_df, preprocessed_df = prime_dataset()","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:33:51.120616Z","iopub.execute_input":"2024-09-10T02:33:51.120873Z","iopub.status.idle":"2024-09-10T02:33:51.410888Z","shell.execute_reply.started":"2024-09-10T02:33:51.12085Z","shell.execute_reply":"2024-09-10T02:33:51.409889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip uninstall -y wandb","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:33:51.412023Z","iopub.execute_input":"2024-09-10T02:33:51.412305Z","iopub.status.idle":"2024-09-10T02:33:55.44971Z","shell.execute_reply.started":"2024-09-10T02:33:51.41228Z","shell.execute_reply":"2024-09-10T02:33:55.448691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cp /kaggle/working/valid.txt /kaggle/working/yolov9/valid.txt\n!cp /kaggle/working/train.txt /kaggle/working/yolov9/train.txt","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:33:55.456413Z","iopub.execute_input":"2024-09-10T02:33:55.456724Z","iopub.status.idle":"2024-09-10T02:33:57.493071Z","shell.execute_reply.started":"2024-09-10T02:33:55.456695Z","shell.execute_reply":"2024-09-10T02:33:57.491941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rm -rf /kaggle/working/yolov9/runs","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:33:57.494555Z","iopub.execute_input":"2024-09-10T02:33:57.494858Z","iopub.status.idle":"2024-09-10T02:33:58.506097Z","shell.execute_reply.started":"2024-09-10T02:33:57.494831Z","shell.execute_reply":"2024-09-10T02:33:58.504732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_model()","metadata":{"execution":{"iopub.status.busy":"2024-09-10T02:33:58.507837Z","iopub.execute_input":"2024-09-10T02:33:58.508171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!cp /kaggle/working/yolov9/runs/train/exp/weights/last.pt /kaggle/working/lan1.pt","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}