{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":19989,"databundleVersionId":1160143,"isSourceIdPinned":false,"sourceType":"competition"},{"sourceId":211097053,"sourceType":"kernelVersion"},{"sourceId":139474,"sourceType":"modelInstanceVersion","isSourceIdPinned":false,"modelInstanceId":118113,"modelId":141350},{"sourceId":410303,"sourceType":"modelInstanceVersion","isSourceIdPinned":false,"modelInstanceId":335049,"modelId":356067},{"sourceId":412127,"sourceType":"modelInstanceVersion","isSourceIdPinned":true,"modelInstanceId":336465,"modelId":357457}],"dockerImageVersionId":31040,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import os\nimport re\nimport numpy as np\nimport pandas as pd\nimport cv2\nimport matplotlib.pyplot as plt\nfrom sklearn import model_selection\nfrom sklearn.model_selection import train_test_split\nfrom tqdm import tqdm\nimport shutil\nfrom glob import glob","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-05-25T23:41:39.850322Z","iopub.execute_input":"2025-05-25T23:41:39.850597Z","iopub.status.idle":"2025-05-25T23:41:41.298421Z","shell.execute_reply.started":"2025-05-25T23:41:39.850575Z","shell.execute_reply":"2025-05-25T23:41:41.297547Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!tar xzvf /kaggle/input/ultralytics-for-offline-install/archive.tar.gz\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-25T23:41:41.299726Z","iopub.execute_input":"2025-05-25T23:41:41.300202Z","iopub.status.idle":"2025-05-25T23:42:42.718876Z","shell.execute_reply.started":"2025-05-25T23:41:41.300170Z","shell.execute_reply":"2025-05-25T23:42:42.717283Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip install --no-index --no-deps --find-links=./packages ultralytics","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-25T23:42:42.721381Z","iopub.execute_input":"2025-05-25T23:42:42.721732Z","iopub.status.idle":"2025-05-25T23:42:49.007296Z","shell.execute_reply.started":"2025-05-25T23:42:42.721698Z","shell.execute_reply":"2025-05-25T23:42:49.005600Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from ultralytics import YOLO\nmodel = YOLO('/kaggle/input/global-wheat-detection-yolov11n-v2/pytorch/default/1/custom_yolo (1).pt')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-25T23:42:49.009888Z","iopub.execute_input":"2025-05-25T23:42:49.010398Z","iopub.status.idle":"2025-05-25T23:42:58.577424Z","shell.execute_reply.started":"2025-05-25T23:42:49.010333Z","shell.execute_reply":"2025-05-25T23:42:58.576472Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_dir = \"/kaggle/input/global-wheat-detection/test\"\ntest_images = sorted(glob(os.path.join(test_dir, \"*.jpg\")))\n\nresults = []\n\nfor image_path in test_images:\n    image_id = os.path.splitext(os.path.basename(image_path))[0]\n    preds = model.predict(source=image_path, conf=0.5, iou=0.5, save=False, verbose=False)\n    boxes = preds[0].boxes\n    prediction_string = \"\"\n    for xyxy, score in zip(boxes.xyxy.cpu().numpy(), boxes.conf.cpu().numpy()):\n        x_min, y_min, x_max, y_max = xyxy\n        width = x_max - x_min\n        height = y_max - y_min\n        prediction_string += f\"{score:.4f} {int(x_min)} {int(y_min)} {int(width)} {int(height)} \"\n\n    results.append({\n        \"image_id\": image_id,\n        \"PredictionString\": prediction_string.strip()\n    })\n\nprint(results[:2])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-25T23:42:58.578604Z","iopub.execute_input":"2025-05-25T23:42:58.579564Z","iopub.status.idle":"2025-05-25T23:43:05.802780Z","shell.execute_reply.started":"2025-05-25T23:42:58.579529Z","shell.execute_reply":"2025-05-25T23:43:05.801739Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission_df = pd.DataFrame(results)\nprint(submission_df.head())\nsubmission_df.to_csv(\"submission.csv\", index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-05-25T23:43:05.803875Z","iopub.execute_input":"2025-05-25T23:43:05.804298Z","iopub.status.idle":"2025-05-25T23:43:05.835200Z","shell.execute_reply.started":"2025-05-25T23:43:05.804262Z","shell.execute_reply":"2025-05-25T23:43:05.834432Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}