Dirake commited on
Commit
acbc0af
·
verified ·
1 Parent(s): 2649531

Upload 13 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ after_train/labels.jfif filter=lfs diff=lfs merge=lfs -text
37
+ after_train/results.png filter=lfs diff=lfs merge=lfs -text
38
+ result.gif filter=lfs diff=lfs merge=lfs -text
39
+ result/result_2.mp4 filter=lfs diff=lfs merge=lfs -text
40
+ result/result.mp4 filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,12 +1,29 @@
1
- ---
2
- title: Pokemon2
3
- emoji: 📈
4
- colorFrom: green
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 5.49.1
8
- app_file: app.py
9
- pinned: false
10
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ # Pokemon object detections
2
+ Using yolov8 after training with Google Colab
3
+ ## Dataset
4
+ Because of lack of data, there are only 7 classes: ```pikachu```, ```charmander```, ```bulbasaur```, ```squirtle```, ```eevee```, ```jigglypuff``` and ```other```.
5
+
6
+ ![labels](https://github.com/vovod/yolov8-pokemon-object-detection/blob/main/after_train/labels.jfif)
7
+ ## Requirements
8
+ ```
9
+ pip install ultralytics
10
+ ```
11
+ ## Preprocess Data
12
+ The ```convert.py``` used to convert *.xml* label file to *.txt* yolo label file.
13
+ Run ```resize_image.py``` to resize image's width to 640.
14
+ ## Train with Colab
15
+ Edit ```name.yaml```.
16
+ Upload images and labels.
17
+ ```
18
+ !yolo train model=yolov8n.pt data=/content/name.yaml epochs=50 imgsz=640
19
+ ```
20
+ ## Training's Result
21
+ ```last.pt``` and ```best.pt``` in result folder.
22
+
23
+ ![train](https://github.com/vovod/yolov8-pokemon-object-detection/blob/main/after_train/results.png?raw=true)
24
+ ## Predict
25
+ Run ```predict.py``` to see result. This is my predict to ```test.mp4```:
26
+
27
+ ![result](https://github.com/vovod/yolov8-pokemon-object-detection/blob/main/result.gif?raw=true)
28
 
29
+ #### Thank you for stopping by!
after_train/labels.jfif ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7ab28834a9d80d80bf222ea9bd195ba3fb43fa28778fa478106a1bad4d69df5c
3
+ size 233258
after_train/results.png ADDED

Git LFS Details

  • SHA256: 8bd5e81234e72def54d070b260aeca6098df9fef0e4c12785e7ddfe2154e20f5
  • Pointer size: 131 Bytes
  • Size of remote file: 244 kB
convert.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from xml.dom import minidom
4
+ import os
5
+ import glob
6
+
7
+ lut={}
8
+ lut["pikachu"]=0
9
+ lut["charmander"]=1
10
+ lut["bulbasaur"]=2
11
+ lut["squirtle"]=3
12
+ lut["eevee"]=4
13
+ lut["other"]=5
14
+ lut["jigglypuff"]=6
15
+
16
+
17
+ def convert_coordinates(size, box):
18
+ if(size[0]==0 or size[1]==0):
19
+ return (0,0,0,0)
20
+ dw = 1.0/size[0]
21
+ dh = 1.0/size[1]
22
+ x = (box[0]+box[1])/2.0
23
+ y = (box[2]+box[3])/2.0
24
+ w = box[1]-box[0]
25
+ h = box[3]-box[2]
26
+ x = x*dw
27
+ w = w*dw
28
+ y = y*dh
29
+ h = h*dh
30
+ return (x,y,w,h)
31
+
32
+
33
+ def convert_xml2yolo(lut):
34
+
35
+ for fname in glob.glob("*.xml"):
36
+
37
+ xmldoc = minidom.parse(fname)
38
+
39
+ fname_out = (fname[:-4]+'.txt')
40
+
41
+ with open(fname_out, "w") as f:
42
+
43
+ itemlist = xmldoc.getElementsByTagName('object')
44
+ size = xmldoc.getElementsByTagName('size')[0]
45
+ width = int((size.getElementsByTagName('width')[0]).firstChild.data)
46
+ height = int((size.getElementsByTagName('height')[0]).firstChild.data)
47
+
48
+ for item in itemlist:
49
+ # get class label
50
+ classid = (item.getElementsByTagName('name')[0]).firstChild.data
51
+ if classid in lut:
52
+ label_str = str(lut[classid])
53
+ else:
54
+ label_str = "-1"
55
+ print ("warning: label '%s' not in look-up table" % classid)
56
+
57
+ # get bbox coordinates
58
+ xmin = ((item.getElementsByTagName('bndbox')[0]).getElementsByTagName('xmin')[0]).firstChild.data
59
+ ymin = ((item.getElementsByTagName('bndbox')[0]).getElementsByTagName('ymin')[0]).firstChild.data
60
+ xmax = ((item.getElementsByTagName('bndbox')[0]).getElementsByTagName('xmax')[0]).firstChild.data
61
+ ymax = ((item.getElementsByTagName('bndbox')[0]).getElementsByTagName('ymax')[0]).firstChild.data
62
+ b = (float(xmin), float(xmax), float(ymin), float(ymax))
63
+ bb = convert_coordinates((width,height), b)
64
+ #print(bb)
65
+
66
+ f.write(label_str + " " + " ".join([("%.6f" % a) for a in bb]) + '\n')
67
+
68
+ print ("wrote %s" % fname_out)
69
+
70
+
71
+
72
+ def main():
73
+ convert_xml2yolo(lut)
74
+
75
+
76
+ if __name__ == '__main__':
77
+ main()
name.yaml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2
+ # COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics
3
+ # Example usage: python train.py --data coco128.yaml
4
+ # parent
5
+ # ├── yolov5
6
+ # └── datasets
7
+ # └── coco128 ← downloads here (7 MB)
8
+
9
+
10
+ # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
11
+ path: ../datasets/name # dataset root dir
12
+ train: images/train # train images (relative to 'path') 128 images
13
+ val: images/train # val images (relative to 'path') 128 images
14
+ test: # test images (optional)
15
+
16
+ # Classes
17
+ names:
18
+ 0: pikachu
19
+ 1: charmander
20
+ 2: bulbasaur
21
+ 3: squirtle
22
+ 4: eevee
23
+ 5: other
24
+ 6: jigglypuff
25
+
26
+
27
+ # Download script/URL (optional)
28
+ download: https://ultralytics.com/assets/coco128.zip
predict.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ultralytics
2
+ from ultralytics import YOLO
3
+ ultralytics.checks()
4
+ import torch
5
+
6
+ device = 'cuda'
7
+
8
+ model = YOLO("best.pt")
9
+ path ="test.mp4"
10
+
11
+ results = model.predict(source=path, show = True)
resize_image.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import os
3
+ from tqdm import tqdm
4
+
5
+ in_file = "E:\\data\\pokemon_classify\\images\\test\\"
6
+ out_file = "E:\\data\\pokemon_classify\\resize_image\\test\\"
7
+
8
+ dict_file = os.listdir(in_file)
9
+
10
+ def main(dict_file, in_file, out_file):
11
+ for file in tqdm(dict_file):
12
+ img = Image.open(in_file + file)
13
+ w,h = img.size
14
+ ratio = w/h
15
+ new_w = 640
16
+ new_h = int(new_w/ratio)
17
+ new_img = img.resize((new_w,new_h), Image.ANTIALIAS)
18
+ file = file[:-4] + '.jpg'
19
+ new_img.save(out_file + file, quality = 100)
20
+
21
+ if __name__ == '__main__':
22
+ main(dict_file, in_file, out_file)
result.gif ADDED

Git LFS Details

  • SHA256: cc097a38f57b902d06af448a1232984c6b0df18fecba15bde0fc1269fd062d00
  • Pointer size: 133 Bytes
  • Size of remote file: 17.5 MB
result/best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e817c0e164e80cd3cafb502ccb17d4ab2c98cfe18894980973a18d9b1b0ac58
3
+ size 6210936
result/last.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7dc1bbb6403aa7a87940e46dab3f33aa4686b2d9013edc33243539d80ecc03bf
3
+ size 6210936
result/result.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac418ee5c59d60e1c0b830ea592ac522b97c3158d0862b7cf25edcfb7c5bb49f
3
+ size 40649916
result/result_2.mp4 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aeb70e20a7cd1f4de65b5b596de7416d435d31f8ba3e9f0ceaf0c4fe9315ca4f
3
+ size 44911056
yolov8-pokemon-object-detection-main.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6a1ce7dc3391a438c069135983d5ad12b3ea4066d9dbcbd0d14d25f3c24c58a2
3
+ size 106562285