add new models

This commit is contained in:
Ryan 2023-06-29 23:49:53 +08:00
parent 42c86e80ba
commit a8c5b736b9
161 changed files with 702 additions and 43 deletions
.gitignoredownload.py
example
demo.py
image
182786930_7ea28fa4e5_b.jpg19749927709_0fc8e147f4_c.jpg1_3B491ZMKZXn_8wNZzzmLjw.png2216426419_5ecce6a9b7_b.jpg2216427485_4ab4a0ab15_b.jpg26042575973_bec0ee4ed3_c.jpg262351090_cce46a3aaf_b.jpg262351090_cce46a3aaf_c.jpg2637982077_a3eae26779.jpg26580716151_231617fa62_c.jpg3141147409_a21cf55a3f_b.jpg3141148575_fa707caa51_b.jpg3192850778_a357a8c4eb_b.jpg3248900478_6c4a6820f7_c.jpg345056969_e9cdec3f5b_b.jpg3790917644_1439edce15_b.jpg3790917644_1439edce15_c.jpg391652196_caa374fa66_c.jpg4032144165_ae06416f49_b.jpg4032144629_74fccbaa55_b.jpg443608310_c7a2c5c461_b.jpg443608310_c7a2c5c461_c.jpg4438771159_d7534ae13e_b.jpg45417730904_0ca22a249b_c.jpg4576880057_1da8f15531_c.jpg4590208246_9fe6b3ba4e_b.jpg4b0cb73667375a39.jpeg5080604905_a3fa44daa2_c.jpg517635286_226efba7b5_z.jpg52919232835_7efa5ba569_c.jpg5345628611_c298fc968b_c.jpg5348993466_40cde6a06d_c.jpg5751900082_3b019aa0f3_c.jpg6324133464_9605f83c27_c.jpg6364195427_0dca317ef3_c.jpg7454489180_bf2aeb87de_c.jpgFIKXSKACURH2DK7M6K6QTPZN5U.jpgIMG_20230627_092146.jpgOIP-C (1) (1).jpgOIP-C (1).jpgOIP-C (10) (1).jpgOIP-C (10).jpgOIP-C (11) (1).jpgOIP-C (11).jpgOIP-C (12) (1).jpgOIP-C (12).jpgOIP-C (13).jpgOIP-C (14).jpgOIP-C (15).jpgOIP-C (16).jpgOIP-C (17).jpgOIP-C (18).jpgOIP-C (19).jpgOIP-C (2) (1).jpgOIP-C (2).jpgOIP-C (20).jpgOIP-C (21).jpgOIP-C (22).jpgOIP-C (23).jpgOIP-C (24).jpgOIP-C (25).jpgOIP-C (3) (1).jpgOIP-C (3).jpgOIP-C (4) (1).jpgOIP-C (4).jpgOIP-C (5) (1).jpgOIP-C (5).jpgOIP-C (6) (1).jpgOIP-C (6).jpgOIP-C (7) (1).jpgOIP-C (7).jpgOIP-C (8) (1).jpgOIP-C (8).jpgOIP-C (9) (1).jpgOIP-C (9).jpgOIP-C.jpgUntitled.jpgbook.jpgboosdaf.jpgimages.jpgkey.jpgmaxresdefault.jpgmix.pngrubik.jpgrubikscube-2048px-08408.jpgsadf.jpgsasd.jpg
video.py
video
yolov8n.pt
runs/detect/train2

2
.gitignore vendored
View file

@ -1 +1,3 @@
virtualenv/
dataset-obj365/
dataset-rubick/

58
download.py Normal file
View file

@ -0,0 +1,58 @@
from tqdm import tqdm
from ultralytics.yolo.utils.checks import check_requirements
from ultralytics.yolo.utils.downloads import download
from ultralytics.yolo.utils.ops import xyxy2xywhn
import numpy as np
from pathlib import Path
check_requirements(('pycocotools>=2.0',))
from pycocotools.coco import COCO
# Make Directories
dir = Path(yaml['path']) # dataset root dir
for p in 'images', 'labels':
(dir / p).mkdir(parents=True, exist_ok=True)
for q in 'train', 'val':
(dir / p / q).mkdir(parents=True, exist_ok=True)
# Train, Val Splits
for split, patches in [('train', 50 + 1), ('val', 43 + 1)]:
print(f"Processing {split} in {patches} patches ...")
images, labels = dir / 'images' / split, dir / 'labels' / split
# Download
url = f"https://dorc.ks3-cn-beijing.ksyun.com/data-set/2020Objects365%E6%95%B0%E6%8D%AE%E9%9B%86/{split}/"
if split == 'train':
download([f'{url}zhiyuan_objv2_{split}.tar.gz'], dir=dir) # annotations json
download([f'{url}patch{i}.tar.gz' for i in range(patches)], dir=images, curl=True, threads=8)
elif split == 'val':
download([f'{url}zhiyuan_objv2_{split}.json'], dir=dir) # annotations json
download([f'{url}images/v1/patch{i}.tar.gz' for i in range(15 + 1)], dir=images, curl=True, threads=8)
download([f'{url}images/v2/patch{i}.tar.gz' for i in range(16, patches)], dir=images, curl=True, threads=8)
# Move
for f in tqdm(images.rglob('*.jpg'), desc=f'Moving {split} images'):
f.rename(images / f.name) # move to /images/{split}
# Labels
coco = COCO(dir / f'zhiyuan_objv2_{split}.json')
names = [x["name"] for x in coco.loadCats(coco.getCatIds())]
for cid, cat in enumerate(names):
catIds = coco.getCatIds(catNms=[cat])
imgIds = coco.getImgIds(catIds=catIds)
for im in tqdm(coco.loadImgs(imgIds), desc=f'Class {cid + 1}/{len(names)} {cat}'):
width, height = im["width"], im["height"]
path = Path(im["file_name"]) # image filename
try:
with open(labels / path.with_suffix('.txt').name, 'a') as file:
annIds = coco.getAnnIds(imgIds=im["id"], catIds=catIds, iscrowd=None)
for a in coco.loadAnns(annIds):
x, y, w, h = a['bbox'] # bounding box in xywh (xy top-left corner)
xyxy = np.array([x, y, x + w, y + h])[None] # pixels(1,4)
x, y, w, h = xyxy2xywhn(xyxy, w=width, h=height, clip=True)[0] # normalized and clipped
file.write(f"{cid} {x:.5f} {y:.5f} {w:.5f} {h:.5f}\n")
except Exception as e:
print(e)

View file

@ -1,53 +1,20 @@
from ultralytics import YOLO
# from ultralytics.yolo.utils.benchmarks import benchmark
import cv2
# Load a model
# model = YOLO("yolov8n.yaml") # build a new model from scratch
model = YOLO("yolov8n.pt") # load a pretrained model (recommended for training)
# model = YOLO("../runs/detect/train3/weights/best.pt") # zhou
model = YOLO("../runs/detect/train4/weights/best.pt") # 1000 img, mine
model = YOLO("../runs/detect/train2/weights/best.pt") # 1000 img, based on 3000 img
# model = YOLO("../../../project/runs/detect/train3/weights/best.pt") # 3000 img, mine
# Use the model
# model.train(data="coco128.yaml", epochs=3,workers=0) # train the model,workers=0 if windows
# metrics = model.val() # evaluate model performance on the validation set
'''
results = model("bus.jpg") # predict on an image
print(results)
# '''
img_path = "./image/"
# results = model.predict(img_path, save=True,conf=0.5) # device=0 by default, conf:置信度阈值
img_path = "./image"
results = model.predict(img_path, save = True) # device=0 by default, conf:置信度阈值
# results = model.predict(img_path,save=True,classes=[0,2],conf=0.5) # i.e. classes=0,classes=[0,3,4]
# save detection results *
# results = model.predict(img_path,save=True,save_txt=True,classes=0,conf=0.4)
# predict video
video_path = "./video/1.mp4"
cap = cv2.VideoCapture(0)
# Loop through the video frames
while cap.isOpened():
# Read a frame from the video
success, frame = cap.read()
if success:
# Run YOLOv8 inference on the frame
results = model(frame)
# Visualize the results on the frame
annotated_frame = results[0].plot()
# Display the annotated frame
cv2.imshow("YOLOv8 Inference", annotated_frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord("q"):
break
else:
# Break the loop if the end of the video is reached
break
# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()

Binary file not shown.

After

(image error) Size: 157 KiB

View file

Before

(image error) Size: 94 KiB

After

(image error) Size: 94 KiB

View file

Before

(image error) Size: 254 KiB

After

(image error) Size: 254 KiB

View file

Before

(image error) Size: 86 KiB

After

(image error) Size: 86 KiB

View file

Before

(image error) Size: 86 KiB

After

(image error) Size: 86 KiB

View file

Before

(image error) Size: 67 KiB

After

(image error) Size: 67 KiB

View file

Before

(image error) Size: 167 KiB

After

(image error) Size: 167 KiB

View file

Before

(image error) Size: 122 KiB

After

(image error) Size: 122 KiB

View file

Before

(image error) Size: 116 KiB

After

(image error) Size: 116 KiB

View file

Before

(image error) Size: 61 KiB

After

(image error) Size: 61 KiB

View file

Before

(image error) Size: 81 KiB

After

(image error) Size: 81 KiB

View file

Before

(image error) Size: 67 KiB

After

(image error) Size: 67 KiB

Binary file not shown.

After

(image error) Size: 40 KiB

View file

Before

(image error) Size: 67 KiB

After

(image error) Size: 67 KiB

View file

Before

(image error) Size: 80 KiB

After

(image error) Size: 80 KiB

View file

Before

(image error) Size: 86 KiB

After

(image error) Size: 86 KiB

View file

Before

(image error) Size: 66 KiB

After

(image error) Size: 66 KiB

View file

Before

(image error) Size: 71 KiB

After

(image error) Size: 71 KiB

View file

Before

(image error) Size: 194 KiB

After

(image error) Size: 194 KiB

View file

Before

(image error) Size: 126 KiB

After

(image error) Size: 126 KiB

View file

Before

(image error) Size: 113 KiB

After

(image error) Size: 113 KiB

View file

Before

(image error) Size: 85 KiB

After

(image error) Size: 85 KiB

View file

Before

(image error) Size: 123 KiB

After

(image error) Size: 123 KiB

View file

Before

(image error) Size: 99 KiB

After

(image error) Size: 99 KiB

View file

Before

(image error) Size: 216 KiB

After

(image error) Size: 216 KiB

View file

Before

(image error) Size: 104 KiB

After

(image error) Size: 104 KiB

Binary file not shown.

After

(image error) Size: 183 KiB

View file

Before

(image error) Size: 77 KiB

After

(image error) Size: 77 KiB

View file

Before

(image error) Size: 48 KiB

After

(image error) Size: 48 KiB

View file

Before

(image error) Size: 48 KiB

After

(image error) Size: 48 KiB

View file

Before

(image error) Size: 73 KiB

After

(image error) Size: 73 KiB

View file

Before

(image error) Size: 50 KiB

After

(image error) Size: 50 KiB

View file

Before

(image error) Size: 151 KiB

After

(image error) Size: 151 KiB

View file

Before

(image error) Size: 88 KiB

After

(image error) Size: 88 KiB

View file

Before

(image error) Size: 63 KiB

After

(image error) Size: 63 KiB

View file

Before

(image error) Size: 110 KiB

After

(image error) Size: 110 KiB

View file

Before

(image error) Size: 3.5 MiB

After

(image error) Size: 3.5 MiB

Binary file not shown.

After

(image error) Size: 4.2 MiB

Binary file not shown.

After

(image error) Size: 15 KiB

View file

Before

(image error) Size: 9.1 KiB

After

(image error) Size: 9.1 KiB

Binary file not shown.

After

(image error) Size: 11 KiB

View file

Before

(image error) Size: 17 KiB

After

(image error) Size: 17 KiB

Binary file not shown.

After

(image error) Size: 7.2 KiB

View file

Before

(image error) Size: 26 KiB

After

(image error) Size: 26 KiB

Binary file not shown.

After

(image error) Size: 11 KiB

Binary file not shown.

After

(image error) Size: 8.9 KiB

Binary file not shown.

After

(image error) Size: 8.2 KiB

Binary file not shown.

After

(image error) Size: 10 KiB

Binary file not shown.

After

(image error) Size: 10 KiB

Binary file not shown.

After

(image error) Size: 14 KiB

Binary file not shown.

After

(image error) Size: 13 KiB

Binary file not shown.

After

(image error) Size: 4.5 KiB

Binary file not shown.

After

(image error) Size: 15 KiB

Binary file not shown.

After

(image error) Size: 6 KiB

View file

Before

(image error) Size: 11 KiB

After

(image error) Size: 11 KiB

Binary file not shown.

After

(image error) Size: 7.2 KiB

Binary file not shown.

After

(image error) Size: 7.7 KiB

Binary file not shown.

After

(image error) Size: 4.4 KiB

View file

Before

(image error) Size: 15 KiB

After

(image error) Size: 15 KiB

View file

Before

(image error) Size: 9.8 KiB

After

(image error) Size: 9.8 KiB

View file

Before

(image error) Size: 11 KiB

After

(image error) Size: 11 KiB

Binary file not shown.

After

(image error) Size: 4.9 KiB

View file

Before

(image error) Size: 12 KiB

After

(image error) Size: 12 KiB

Binary file not shown.

After

(image error) Size: 7.1 KiB

View file

Before

(image error) Size: 6.4 KiB

After

(image error) Size: 6.4 KiB

Binary file not shown.

After

(image error) Size: 9.4 KiB

View file

Before

(image error) Size: 10 KiB

After

(image error) Size: 10 KiB

Binary file not shown.

After

(image error) Size: 7.9 KiB

View file

Before

(image error) Size: 12 KiB

After

(image error) Size: 12 KiB

Binary file not shown.

After

(image error) Size: 8.6 KiB

View file

Before

(image error) Size: 18 KiB

After

(image error) Size: 18 KiB

Binary file not shown.

After

(image error) Size: 9.3 KiB

View file

Before

(image error) Size: 12 KiB

After

(image error) Size: 12 KiB

Binary file not shown.

After

(image error) Size: 30 KiB

View file

Before

(image error) Size: 17 KiB

After

(image error) Size: 17 KiB

View file

Before

(image error) Size: 14 KiB

After

(image error) Size: 14 KiB

BIN
example/image/Untitled.jpg Normal file

Binary file not shown.

After

(image error) Size: 5.2 KiB

BIN
example/image/book.jpg Normal file

Binary file not shown.

After

(image error) Size: 9.5 KiB

BIN
example/image/boosdaf.jpg Normal file

Binary file not shown.

After

(image error) Size: 21 KiB

BIN
example/image/images.jpg Normal file

Binary file not shown.

After

(image error) Size: 8.6 KiB

BIN
example/image/key.jpg Normal file

Binary file not shown.

After

(image error) Size: 5.1 KiB

View file

Before

(image error) Size: 122 KiB

After

(image error) Size: 122 KiB

BIN
example/image/mix.png Normal file

Binary file not shown.

After

(image error) Size: 873 KiB

BIN
example/image/rubik.jpg Normal file

Binary file not shown.

After

(image error) Size: 6.8 KiB

View file

Before

(image error) Size: 98 KiB

After

(image error) Size: 98 KiB

BIN
example/image/sadf.jpg Normal file

Binary file not shown.

After

(image error) Size: 5.3 KiB

BIN
example/image/sasd.jpg Normal file

Binary file not shown.

After

(image error) Size: 4.1 KiB

39
example/video.py Normal file
View file

@ -0,0 +1,39 @@
import cv2
from ultralytics import YOLO
# Load the YOLOv8 model
# model = YOLO("../runs/detect/train3/weights/best.pt") # zhou
# model = YOLO("../runs/detect/train4/weights/best.pt") # 1000 img, mine
# model = YOLO("../runs/detect/train2/weights/best.pt") # 1000 img, based on 3000 img
model = YOLO("../../../project/runs/detect/train3/weights/best.pt") # 3000 img, mine
# Open the video file
video_path = "./video/demo_video_no_detection.mp4"
cap = cv2.VideoCapture(video_path)
# Loop through the video frames
while cap.isOpened():
# Read a frame from the video
success, frame = cap.read()
if success:
# Run YOLOv8 inference on the frame
results = model(frame)
# Visualize the results on the frame
annotated_frame = results[0].plot()
# Display the annotated frame
cv2.imshow("YOLOv8 Inference", annotated_frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord("q"):
break
else:
# Break the loop if the end of the video is reached
break
# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()

BIN
example/video/demo_keys.mp4 Normal file

Binary file not shown.

Binary file not shown.

BIN
example/yolov8n.pt Normal file

Binary file not shown.

Binary file not shown.

After

(image error) Size: 156 KiB

Binary file not shown.

After

(image error) Size: 131 KiB

Binary file not shown.

After

(image error) Size: 134 KiB

Binary file not shown.

After

(image error) Size: 148 KiB

View file

@ -0,0 +1,97 @@
task: detect
mode: train
model: ../../project/runs/detect/train3/weights/best.pt
data: ../datasets/zcxv.v2i.yolov8/data.yaml
epochs: 100
patience: 50
batch: 16
imgsz: 640
save: true
save_period: -1
cache: false
device: cuda
workers: 8
project: null
name: null
exist_ok: false
pretrained: true
optimizer: auto
verbose: true
seed: 0
deterministic: true
single_cls: false
rect: false
cos_lr: false
close_mosaic: 0
resume: false
amp: true
fraction: 1.0
profile: false
overlap_mask: true
mask_ratio: 4
dropout: 0.0
val: true
split: val
save_json: false
save_hybrid: false
conf: null
iou: 0.7
max_det: 300
half: false
dnn: false
plots: true
source: null
show: false
save_txt: false
save_conf: false
save_crop: false
show_labels: true
show_conf: true
vid_stride: 1
line_width: null
visualize: false
augment: false
agnostic_nms: false
classes: null
retina_masks: false
boxes: true
format: torchscript
keras: false
optimize: false
int8: false
dynamic: false
simplify: false
opset: null
workspace: 4
nms: false
lr0: 0.01
lrf: 0.01
momentum: 0.937
weight_decay: 0.0005
warmup_epochs: 3.0
warmup_momentum: 0.8
warmup_bias_lr: 0.1
box: 7.5
cls: 0.5
dfl: 1.5
pose: 12.0
kobj: 1.0
label_smoothing: 0.0
nbs: 64
hsv_h: 0.015
hsv_s: 0.7
hsv_v: 0.4
degrees: 0.0
translate: 0.1
scale: 0.5
shear: 0.0
perspective: 0.0
flipud: 0.0
fliplr: 0.5
mosaic: 1.0
mixup: 0.0
copy_paste: 0.0
cfg: null
v5loader: false
tracker: botsort.yaml
save_dir: /home/ryan/Documents/School/2023t1/dnb/project/runs/detect/train2

Binary file not shown.

After

(image error) Size: 99 KiB

Some files were not shown because too many files have changed in this diff Show more