add new models
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
|||
virtualenv/
|
||||
dataset-obj365/
|
||||
dataset-rubick/
|
||||
|
|
58
download.py
Normal 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)
|
||||
|
|
@ -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()
|
||||
|
|
BIN
example/image/182786930_7ea28fa4e5_b.jpg
Normal file
After ![]() (image error) Size: 157 KiB |
Before ![]() (image error) Size: 94 KiB After ![]() (image error) Size: 94 KiB ![]() ![]() |
Before ![]() (image error) Size: 254 KiB After ![]() (image error) Size: 254 KiB ![]() ![]() |
Before ![]() (image error) Size: 86 KiB After ![]() (image error) Size: 86 KiB ![]() ![]() |
Before ![]() (image error) Size: 86 KiB After ![]() (image error) Size: 86 KiB ![]() ![]() |
Before ![]() (image error) Size: 67 KiB After ![]() (image error) Size: 67 KiB ![]() ![]() |
Before ![]() (image error) Size: 167 KiB After ![]() (image error) Size: 167 KiB ![]() ![]() |
Before ![]() (image error) Size: 122 KiB After ![]() (image error) Size: 122 KiB ![]() ![]() |
Before ![]() (image error) Size: 116 KiB After ![]() (image error) Size: 116 KiB ![]() ![]() |
Before ![]() (image error) Size: 61 KiB After ![]() (image error) Size: 61 KiB ![]() ![]() |
Before ![]() (image error) Size: 81 KiB After ![]() (image error) Size: 81 KiB ![]() ![]() |
Before ![]() (image error) Size: 67 KiB After ![]() (image error) Size: 67 KiB ![]() ![]() |
BIN
example/image/3192850778_a357a8c4eb_b.jpg
Normal file
After ![]() (image error) Size: 40 KiB |
Before ![]() (image error) Size: 67 KiB After ![]() (image error) Size: 67 KiB ![]() ![]() |
Before ![]() (image error) Size: 80 KiB After ![]() (image error) Size: 80 KiB ![]() ![]() |
Before ![]() (image error) Size: 86 KiB After ![]() (image error) Size: 86 KiB ![]() ![]() |
Before ![]() (image error) Size: 66 KiB After ![]() (image error) Size: 66 KiB ![]() ![]() |
Before ![]() (image error) Size: 71 KiB After ![]() (image error) Size: 71 KiB ![]() ![]() |
Before ![]() (image error) Size: 194 KiB After ![]() (image error) Size: 194 KiB ![]() ![]() |
Before ![]() (image error) Size: 126 KiB After ![]() (image error) Size: 126 KiB ![]() ![]() |
Before ![]() (image error) Size: 113 KiB After ![]() (image error) Size: 113 KiB ![]() ![]() |
Before ![]() (image error) Size: 85 KiB After ![]() (image error) Size: 85 KiB ![]() ![]() |
Before ![]() (image error) Size: 123 KiB After ![]() (image error) Size: 123 KiB ![]() ![]() |
Before ![]() (image error) Size: 99 KiB After ![]() (image error) Size: 99 KiB ![]() ![]() |
Before ![]() (image error) Size: 216 KiB After ![]() (image error) Size: 216 KiB ![]() ![]() |
Before ![]() (image error) Size: 104 KiB After ![]() (image error) Size: 104 KiB ![]() ![]() |
BIN
example/image/4b0cb73667375a39.jpeg
Normal file
After ![]() (image error) Size: 183 KiB |
Before ![]() (image error) Size: 77 KiB After ![]() (image error) Size: 77 KiB ![]() ![]() |
Before ![]() (image error) Size: 48 KiB After ![]() (image error) Size: 48 KiB ![]() ![]() |
Before ![]() (image error) Size: 48 KiB After ![]() (image error) Size: 48 KiB ![]() ![]() |
Before ![]() (image error) Size: 73 KiB After ![]() (image error) Size: 73 KiB ![]() ![]() |
Before ![]() (image error) Size: 50 KiB After ![]() (image error) Size: 50 KiB ![]() ![]() |
Before ![]() (image error) Size: 151 KiB After ![]() (image error) Size: 151 KiB ![]() ![]() |
Before ![]() (image error) Size: 88 KiB After ![]() (image error) Size: 88 KiB ![]() ![]() |
Before ![]() (image error) Size: 63 KiB After ![]() (image error) Size: 63 KiB ![]() ![]() |
Before ![]() (image error) Size: 110 KiB After ![]() (image error) Size: 110 KiB ![]() ![]() |
Before ![]() (image error) Size: 3.5 MiB After ![]() (image error) Size: 3.5 MiB ![]() ![]() |
BIN
example/image/IMG_20230627_092146.jpg
Normal file
After ![]() (image error) Size: 4.2 MiB |
BIN
example/image/OIP-C (1) (1).jpg
Normal file
After ![]() (image error) Size: 15 KiB |
Before ![]() (image error) Size: 9.1 KiB After ![]() (image error) Size: 9.1 KiB ![]() ![]() |
BIN
example/image/OIP-C (10) (1).jpg
Normal file
After ![]() (image error) Size: 11 KiB |
Before ![]() (image error) Size: 17 KiB After ![]() (image error) Size: 17 KiB ![]() ![]() |
BIN
example/image/OIP-C (11) (1).jpg
Normal file
After ![]() (image error) Size: 7.2 KiB |
Before ![]() (image error) Size: 26 KiB After ![]() (image error) Size: 26 KiB ![]() ![]() |
BIN
example/image/OIP-C (12) (1).jpg
Normal file
After ![]() (image error) Size: 11 KiB |
BIN
example/image/OIP-C (12).jpg
Normal file
After ![]() (image error) Size: 8.9 KiB |
BIN
example/image/OIP-C (13).jpg
Normal file
After ![]() (image error) Size: 8.2 KiB |
BIN
example/image/OIP-C (14).jpg
Normal file
After ![]() (image error) Size: 10 KiB |
BIN
example/image/OIP-C (15).jpg
Normal file
After ![]() (image error) Size: 10 KiB |
BIN
example/image/OIP-C (16).jpg
Normal file
After ![]() (image error) Size: 14 KiB |
BIN
example/image/OIP-C (17).jpg
Normal file
After ![]() (image error) Size: 13 KiB |
BIN
example/image/OIP-C (18).jpg
Normal file
After ![]() (image error) Size: 4.5 KiB |
BIN
example/image/OIP-C (19).jpg
Normal file
After ![]() (image error) Size: 15 KiB |
BIN
example/image/OIP-C (2) (1).jpg
Normal file
After ![]() (image error) Size: 6 KiB |
Before ![]() (image error) Size: 11 KiB After ![]() (image error) Size: 11 KiB ![]() ![]() |
BIN
example/image/OIP-C (20).jpg
Normal file
After ![]() (image error) Size: 7.2 KiB |
BIN
example/image/OIP-C (21).jpg
Normal file
After ![]() (image error) Size: 7.7 KiB |
BIN
example/image/OIP-C (22).jpg
Normal file
After ![]() (image error) Size: 4.4 KiB |
Before ![]() (image error) Size: 15 KiB After ![]() (image error) Size: 15 KiB ![]() ![]() |
Before ![]() (image error) Size: 9.8 KiB After ![]() (image error) Size: 9.8 KiB ![]() ![]() |
Before ![]() (image error) Size: 11 KiB After ![]() (image error) Size: 11 KiB ![]() ![]() |
BIN
example/image/OIP-C (3) (1).jpg
Normal file
After ![]() (image error) Size: 4.9 KiB |
Before ![]() (image error) Size: 12 KiB After ![]() (image error) Size: 12 KiB ![]() ![]() |
BIN
example/image/OIP-C (4) (1).jpg
Normal file
After ![]() (image error) Size: 7.1 KiB |
Before ![]() (image error) Size: 6.4 KiB After ![]() (image error) Size: 6.4 KiB ![]() ![]() |
BIN
example/image/OIP-C (5) (1).jpg
Normal file
After ![]() (image error) Size: 9.4 KiB |
Before ![]() (image error) Size: 10 KiB After ![]() (image error) Size: 10 KiB ![]() ![]() |
BIN
example/image/OIP-C (6) (1).jpg
Normal file
After ![]() (image error) Size: 7.9 KiB |
Before ![]() (image error) Size: 12 KiB After ![]() (image error) Size: 12 KiB ![]() ![]() |
BIN
example/image/OIP-C (7) (1).jpg
Normal file
After ![]() (image error) Size: 8.6 KiB |
Before ![]() (image error) Size: 18 KiB After ![]() (image error) Size: 18 KiB ![]() ![]() |
BIN
example/image/OIP-C (8) (1).jpg
Normal file
After ![]() (image error) Size: 9.3 KiB |
Before ![]() (image error) Size: 12 KiB After ![]() (image error) Size: 12 KiB ![]() ![]() |
BIN
example/image/OIP-C (9) (1).jpg
Normal file
After ![]() (image error) Size: 30 KiB |
Before ![]() (image error) Size: 17 KiB After ![]() (image error) Size: 17 KiB ![]() ![]() |
Before ![]() (image error) Size: 14 KiB After ![]() (image error) Size: 14 KiB ![]() ![]() |
BIN
example/image/Untitled.jpg
Normal file
After ![]() (image error) Size: 5.2 KiB |
BIN
example/image/book.jpg
Normal file
After ![]() (image error) Size: 9.5 KiB |
BIN
example/image/boosdaf.jpg
Normal file
After ![]() (image error) Size: 21 KiB |
BIN
example/image/images.jpg
Normal file
After ![]() (image error) Size: 8.6 KiB |
BIN
example/image/key.jpg
Normal file
After ![]() (image error) Size: 5.1 KiB |
Before ![]() (image error) Size: 122 KiB After ![]() (image error) Size: 122 KiB ![]() ![]() |
BIN
example/image/mix.png
Normal file
After ![]() (image error) Size: 873 KiB |
BIN
example/image/rubik.jpg
Normal file
After ![]() (image error) Size: 6.8 KiB |
Before ![]() (image error) Size: 98 KiB After ![]() (image error) Size: 98 KiB ![]() ![]() |
BIN
example/image/sadf.jpg
Normal file
After ![]() (image error) Size: 5.3 KiB |
BIN
example/image/sasd.jpg
Normal file
After ![]() (image error) Size: 4.1 KiB |
39
example/video.py
Normal 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
BIN
example/video/demo_video_no_detection.mp4
Normal file
BIN
example/yolov8n.pt
Normal file
BIN
runs/detect/train2/F1_curve.png
Normal file
After ![]() (image error) Size: 156 KiB |
BIN
runs/detect/train2/PR_curve.png
Normal file
After ![]() (image error) Size: 131 KiB |
BIN
runs/detect/train2/P_curve.png
Normal file
After ![]() (image error) Size: 134 KiB |
BIN
runs/detect/train2/R_curve.png
Normal file
After ![]() (image error) Size: 148 KiB |
97
runs/detect/train2/args.yaml
Normal 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
|
BIN
runs/detect/train2/confusion_matrix.png
Normal file
After ![]() (image error) Size: 99 KiB |