Giter Club home page Giter Club logo

Comments (3)

cansik avatar cansik commented on May 18, 2024

I used all the keypoints from the hands in the CMU dataset and calculated the bounding box out of it.

from yolo-hand-detection.

rshigemura avatar rshigemura commented on May 18, 2024

Are you permitted to share the script you used? I'm trying to retrain YOLO from scratch and it would be extremely valuable!!

from yolo-hand-detection.

cansik avatar cansik commented on May 18, 2024

Have a look here, I guess this was script (already some time ago). Please adjust the dataset_name variable to point to the correct dataset.

import glob
import os
import json

from scipy.io import loadmat
from PIL import Image

dataset_name = "test"
dataset = "data\\%s" % dataset_name

data = []
annotations = glob.glob("%s\\*.json" % dataset)

# create annotation dict
ann_map = {}
for ann in annotations:
	key = os.path.splitext(os.path.basename(ann))[0][:-2]
	
	if not key in ann_map:
		ann_map[key] = []

	ann_map[key].append(ann)

def load(file):
    with open(file, 'r') as f:
        return json.load(f)

def write(file, content):
	with open(file, 'w') as outfile:
		outfile.write(content)

def bounding_box(xs, ys):
	x_min = min(xs)
	x_max = max(xs)
	y_min = min(ys)
	y_max = max(ys)

	w = x_max - x_min
	h = y_max - y_min

	return (x_min + (w/2), y_min + (h/2), w, h)

for key in ann_map:
	anns = ann_map[key]
	default_file = os.path.basename(ann_map[key][0])
	default_file_name = os.path.splitext(default_file)[0]

	im = Image.open("%s\\%s.jpg" % (dataset, default_file_name))
	width = im.size[0]
	height = im.size[1]

	ann_txt = []

	for annFile in anns:
		filename = os.path.basename(annFile)
		name = os.path.splitext(filename)[0]
		detections = []

		print(annFile)
		desc = load(annFile)
		keypoints = desc["hand_pts"]

		xs = [l[0] for l in keypoints]
		ys = [l[1] for l in keypoints]
		
		x, y, w, h = bounding_box(xs, ys)

		ann_txt.append("%s %s %s %s %s" % (0, x / width, y / height, w / width, h / height))

	write("%s\\%s.txt" % (dataset, default_file_name), '\n'.join(ann_txt))
	data.append("%s\\%s.jpg" % (dataset, default_file_name))


write("%s.txt" % dataset_name, '\n'.join(data))
print("done!")

from yolo-hand-detection.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.