- Gather some Duck Hunt Game images (min 100 img)
- Label that images
- Export the label data and store in labels folder
- Open yolo v5
- Run setup
- Upload DuckHuntGame.zip
- Unzip DuckHuntGame folder
!unzip -q ../DuckHuntGame.zip -d ../
- Upload custom_data.yaml in yolov5->data section
- Train YOLOv5s on custom_data for min 90 epochs
- Download runs/train/exp2/weights/last.pt or runs/train/exp2/weights/best.pt
Then, your directory structure should look something like this
DuckHuntGame/
ββ images/
ββ train/
ββ val/
ββ labels/
ββ train/
ββ val/
Install
Python>=3.6.0 is required with all requirements.txt installed including PyTorch>=1.7:
$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt
$ pip install PyAutoGUI
$ git clone https://github.com/SOURAB-BAPPA/DuckHuntGame-AI/blob/main/last.pt
Run
import cv2
from grabscreen import grab_screen
import torch
import pyautogui
from PIL import ImageGrab
import numpy as np
import time
# Model
model = torch.hub.load('E:/Hand_Finger_detection/yolov5', 'custom', path='D:/last.pt', source='local') # local repo
while True:
img = grab_screen(region=(0, 0, 1920, 700))
img = cv2.resize(img, (640, 640))
cv2.imshow("Screenshot", img)
results = model(img, size=640)
b1 = results.pandas().xyxy[0]
try:
x, y, xm, ym = int(b1['xmin'][0]), int(b1['ymin'][0]), int(b1['xmax'][0]), int(b1['ymax'][0])
pyautogui.click((x + (xm - x) // 2) * 3, ((y + (ym - y) / 2) * 35) // 32)
except:
pass
results.render() # box selected object
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
cv2.imshow("Result", img)
key = cv2.waitKey(1)
if key == 27:
break
cv2.destroyAllWindows()
CUDA error
- Select based on your system
- Update graphics driver
- This command must run successfully if solved CUDA problem
import torch
torch.zeros(1).cuda()
Training problem
Load YOLOv5
For program bugs and issues or any types of suggestions mail me.