Skip to content

Commit 4429df0

Browse files
author
Shreyas Korde
committed
first commit
0 parents  commit 4429df0

13 files changed

+13
-0
lines changed

Create_Annotation_Files_for_Images.ipynb

+1
Large diffs are not rendered by default.

accuracy_vs_threshold.ipynb

+1
Large diffs are not rendered by default.

custom_dataset_training_files_creation_v2.ipynb

+1
Large diffs are not rendered by default.

darknet

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit ed59050950b5a890a2a1d1c69547250c436a5968

extra_files/Copy of yolov4_custom_v2.ipynb

+1
Large diffs are not rendered by default.

extra_files/Create_Annotation_Files_for_Images.ipynb

+1
Large diffs are not rendered by default.

extra_files/Deployment_v1.ipynb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyPDovvy0luh+t+1VCMwjaN4"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","source":["from google.colab import drive\n","drive.mount('/content/drive')"],"metadata":{"id":"d3x91ZJtaDbv"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["import os\n","!ln -s '/content/drive/My Drive/' /currdrive"],"metadata":{"id":"m44ZtfKtaEoe"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["path = '/currdrive/yolov4'\n","os.chdir(path)"],"metadata":{"id":"YyOtRNMtaErF"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["os.chdir('/currdrive/yolov4/darknet')\n"],"metadata":{"id":"O2vYgfyJaPO-"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":[],"metadata":{"id":"r9BFRzHeaEt-"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"id":"cXmYEdaxZ1of"},"outputs":[],"source":["import cv2\n","import numpy as np\n","\n","# Load YOLOv4 model\n","net = cv2.dnn.readNetFromDarknet('path/to/yolov4.cfg', 'path/to/yolov4.weights')\n","\n","# Get the output layer names\n","layer_names = net.getLayerNames()\n","output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()]\n","\n","# Load video\n","video = cv2.VideoCapture('path/to/video.mp4')\n","\n","# Define classes\n","classes = ['class1', 'class2', 'class3', ...] # Replace with actual class names\n","\n","while True:\n"," # Read a frame from the video\n"," ret, frame = video.read()\n","\n"," if not ret:\n"," break\n","\n"," # Resize frame to match YOLO input size\n"," height, width, _ = frame.shape\n"," scale = 0.00392\n"," blob = cv2.dnn.blobFromImage(frame, scale, (416, 416), (0, 0, 0), True, crop=False)\n","\n"," # Pass the blob through the network\n"," net.setInput(blob)\n"," outs = net.forward(output_layers)\n","\n"," # Initialize empty lists for bounding boxes, confidences, and class IDs\n"," boxes = []\n"," confidences = []\n"," class_ids = []\n","\n"," # Process each output layer\n"," for out in outs:\n"," for detection in out:\n"," scores = detection[5:]\n"," class_id = np.argmax(scores)\n"," confidence = scores[class_id]\n","\n"," if confidence > 0.5: # Adjust confidence threshold as needed\n"," # Calculate bounding box coordinates\n"," center_x = int(detection[0] * width)\n"," center_y = int(detection[1] * height)\n"," w = int(detection[2] * width)\n"," h = int(detection[3] * height)\n"," x = int(center_x - w / 2)\n"," y = int(center_y - h / 2)\n","\n"," # Add bounding box, confidence, and class ID to respective lists\n"," boxes.append([x, y, w, h])\n"," confidences.append(float(confidence))\n"," class_ids.append(class_id)\n","\n"," # Apply non-maximum suppression to eliminate overlapping bounding boxes\n"," indices = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4) # Adjust NMS parameters as needed\n","\n"," # Draw bounding boxes and labels on the frame\n"," for i in indices:\n"," i = i[0]\n"," x, y, w, h = boxes[i]\n"," label = classes[class_ids[i]]\n"," confidence = confidences[i]\n","\n"," # Draw bounding box\n"," cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)\n","\n"," # Write label and confidence\n"," cv2.putText(frame, f'{label}: {confidence:.2f}', (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)\n","\n"," # Display the resulting frame\n"," cv2.imshow('Object Tracking', frame)\n","\n"," # Break loop if 'q' is pressed\n"," if cv2.waitKey(1) & 0xFF == ord('q'):\n"," break\n","\n","# Release resources\n","video.release()\n","cv2.destroyAllWindows()"]}]}

extra_files/custom_dataset_training_files_creation_v1.ipynb

+1
Large diffs are not rendered by default.

extra_files/yolov4.ipynb

+1
Large diffs are not rendered by default.

extra_files/yolov4_custom_v1.ipynb

+1
Large diffs are not rendered by default.

extra_files/yolov4_custom_v2.ipynb

+1
Large diffs are not rendered by default.

video_to_frame.ipynb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyPYHtRzujhUxRAe4WVCOwjD"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","source":["from google.colab import drive\n","drive.mount('/content/drive')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"4CEwxePKM3pM","executionInfo":{"status":"ok","timestamp":1683194407142,"user_tz":-120,"elapsed":30723,"user":{"displayName":"Shreyas Korde","userId":"07415984173285713478"}},"outputId":"4856b3b4-7794-4f3d-b9f4-3b87c8a7ddbd"},"execution_count":null,"outputs":[{"output_type":"stream","name":"stdout","text":["Mounted at /content/drive\n"]}]},{"cell_type":"code","source":["import os\n","!ln -s '/content/drive/My Drive/' /currdrive"],"metadata":{"id":"jsjpGZo1M97b"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["path = '/currdrive/yolov4'\n","os.chdir(path)"],"metadata":{"id":"cgUm8PBZNG1t"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["os.chdir('/currdrive/yolov4/darknet')\n"],"metadata":{"id":"19S-0kmTNL2U"},"execution_count":null,"outputs":[]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":236},"id":"bNoQwxfEMxY9","executionInfo":{"status":"error","timestamp":1683196158405,"user_tz":-120,"elapsed":17291,"user":{"displayName":"Shreyas Korde","userId":"07415984173285713478"}},"outputId":"a2cf500c-77eb-43ee-ad27-a60d4e94c0da"},"outputs":[{"output_type":"error","ename":"error","evalue":"ignored","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31merror\u001b[0m Traceback (most recent call last)","\u001b[0;32m<ipython-input-18-d259cab9af80>\u001b[0m in \u001b[0;36m<cell line: 12>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[0;31m#cv2.imshow(\"Output\", frame)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 16\u001b[0;31m \u001b[0mcv2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mimwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'./drive100/frame'\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcurrentFrame\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m'.jpg'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mframe\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 17\u001b[0m \u001b[0mcurrentFrame\u001b[0m \u001b[0;34m+=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31merror\u001b[0m: OpenCV(4.7.0) /io/opencv/modules/imgcodecs/src/loadsave.cpp:783: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'\n"]}],"source":["import cv2\n","import os\n","\n","vid = cv2.VideoCapture('obj_det_100.avi')\n","currentFrame = 0\n","\n","if not os.path.exists('drive100'):\n"," os.makedirs('drive100')\n"," \n"," \n","\n","while(True):\n"," successs, frame = vid.read()\n"," \n"," #cv2.imshow(\"Output\", frame)\n"," cv2.imwrite('./drive100/frame' + str(currentFrame) + '.jpg', frame)\n"," currentFrame +=1\n"," \n"," if cv2.waitKey(1) & 0xFF == ord('q'):\n"," break\n"," \n","vid.release()\n","cv2.closeALLWindows()\n"]},{"cell_type":"code","source":[],"metadata":{"id":"MMB9RosBNydG"},"execution_count":null,"outputs":[]}]}

yolov4_custom_v3.ipynb

+1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)