Skip to content

Commit

Permalink
Submission Made
Browse files Browse the repository at this point in the history
  • Loading branch information
bersilin-robert1609 committed May 4, 2024
1 parent 8b188f2 commit a759120
Show file tree
Hide file tree
Showing 31 changed files with 5,271 additions and 192 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ bounding_box/
__pycache__/
Object-detection-using-Faster-RCNN
data_4/
data_rcnn/
data_rcnn/
*.zip
172 changes: 172 additions & 0 deletions Starlight_Analysts_Submission/other_files/YOLOv5.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import pandas as pd\n",
"\n",
"from ultralytics import YOLO"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"LABELS = {\n",
" 0: \"aegypti\",\n",
" 1: \"albopictus\",\n",
" 2: \"anopheles\",\n",
" 3: \"culex\",\n",
" 4: \"culiseta\",\n",
" 5: \"japonicus/koreicus\"\n",
"}\n",
"\n",
"# Bounding Box Format: [x_center, y_center, width, height]\n",
"# Output Format: [id, ImageID, LabelName, Conf, xcenter, ycenter, bbx_width, bbx_height] (Indexed from 0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Loading Model\n",
"model = YOLO(model='yolov5nu.pt', task='detect', verbose=True)\n",
"\n",
"# Loading Model in GPU\n",
"model = model.cuda()\n",
"\n",
"arguments = {\n",
" \"project\": \"yolo-experiments\",\n",
" \"name\": \"yolov5n-9\",\n",
" \"data\": \"./data.yaml\",\n",
" \"imgsz\": 640,\n",
" \"batch\": 12,\n",
" \"epochs\": 20,\n",
" \"seed\": 69,\n",
" \"plots\": True,\n",
" \"patience\": 3,\n",
" \n",
" # \"box\": 8,\n",
" # \"cls\": 6,\n",
" # \"pose\": 2,\n",
" # \"hsv_s\": 0.05,\n",
" # \"scale\": 0.0,\n",
" # \"translate\": 0.0,\n",
" # \"fliplr\": 0.0,\n",
" # \"mosaic\": 0.0,\n",
" # \"erasing\": 0.0,\n",
" # \"hsv_v\": 0.05,\n",
" # \"crop_fraction\": 0.1\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Model Training\n",
"results = model.train(**arguments)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"TRAIN_DIR = \"../data_3/images/train\"\n",
"VAL_DIR = \"../data_3/images/val\"\n",
"TEST_DIR = \"../data_3/images/test\"\n",
"\n",
"train_images = os.listdir(TRAIN_DIR)\n",
"val_images = os.listdir(VAL_DIR)\n",
"test_images = os.listdir(TEST_DIR)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"results_test_dataframe = pd.DataFrame(columns=[\"id\", \"ImageID\", \"LabelName\", \"Conf\", \"xcenter\", \"ycenter\", \"bbx_width\", \"bbx_height\"])\n",
"\n",
"# model = YOLO(\"./yolo-experiments/yolov8m-2/weights/best.pt\", task=\"detect\", verbose=True)\n",
"# model = YOLO(model=\"./yolo-experiments/yolov8n-42/weights/best.pt\", task=\"detect\", verbose=True)\n",
"\n",
"results = model(TEST_DIR, stream=True, conf=0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for id, r in enumerate(results):\n",
" r = r.cpu()\n",
" img_path = r.path\n",
" img_name = img_path.split(\"/\")[-1]\n",
" boxes = r.boxes.numpy()\n",
" label = boxes.cls\n",
" conf = boxes.conf\n",
" xywh = boxes.xywhn\n",
" \n",
" # print(label)\n",
" # print(conf)\n",
" \n",
" new_row = {\"id\": id, \"ImageID\": img_name, \"LabelName\": LABELS[int(label[0])], \"Conf\": conf[0], \"xcenter\": xywh[:, 0][0], \"ycenter\": xywh[:, 1][0], \"bbx_width\": xywh[:, 2][0], \"bbx_height\": xywh[:, 3][0]}\n",
" results_test_dataframe = pd.concat([results_test_dataframe, pd.DataFrame([new_row])], ignore_index=True, copy=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"results_test_dataframe.to_csv(\"./submissions/results_test_8.csv\", index=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit a759120

Please sign in to comment.