/DuckHuntGame-AI

In Duck Hunt game Ducks 🦆 are automatically hunted by object detection method. Give a Star 🌟If it helps you.

Primary LanguagePythonMIT LicenseMIT

DuckHuntGame-

Video

Train Custom Model:

  1. Gather some Duck Hunt Game images (min 100 img)
  2. Label that images
  3. Export the label data and store in labels folder
  4. Open yolo v5
CI CPU testing YOLOv5 Citation Docker Pulls
Open In Colab Open In Kaggle Join Forum
  1. Run setup
  2. Upload DuckHuntGame.zip
  3. Unzip DuckHuntGame folder !unzip -q ../DuckHuntGame.zip -d ../
  4. Upload custom_data.yaml in yolov5->data section
  5. Train YOLOv5s on custom_data for min 90 epochs
  6. 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/

Coding Gif


Quick Start Examples

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()

Issues

CUDA error
  1. Select based on your system
  2. Update graphics driver
  3. This command must run successfully if solved CUDA problem
import torch
torch.zeros(1).cuda()

Not Solved

Training problem

Support video

Load YOLOv5

Load YOLOv5 from PyTorch Hub

For program bugs and issues or any types of suggestions mail me.