exemple from sylvain
19
.gitignore
vendored
@ -128,15 +128,20 @@ dmypy.json
|
||||
# node
|
||||
node_modules/
|
||||
*.tar
|
||||
*init.pt
|
||||
*best.pt
|
||||
*.pt
|
||||
|
||||
/yolov7-tracker-example/data/dataset1_2024_06_19/vott-json-export.zip
|
||||
|
||||
/test
|
||||
# /yolov7-setup
|
||||
|
||||
# /yolov7-tracker-example
|
||||
/yolov7-tracker-example/cfg/training/yolov7x_dataset1_2024_06_19.yaml
|
||||
/yolov7-tracker-example/data/dataset1_2024_06_19
|
||||
/yolov7-tracker-example/runs
|
||||
/yolov7-tracker-example/tracker/config_files/dataset1_2024_06_19.yaml
|
||||
/yolov7-tracker-example/wandb
|
||||
/yolov7-tracker-example/info_SF.txt
|
||||
/yolov7-tracker-example/400m.mp4
|
||||
# /yolov7-tracker-example/cfg/training/yolov7x_dataset1_2024_06_19.yaml
|
||||
# /yolov7-tracker-example/data/dataset1_2024_06_19
|
||||
# /yolov7-tracker-example/runs
|
||||
# /yolov7-tracker-example/tracker/config_files/dataset1_2024_06_19.yaml
|
||||
# /yolov7-tracker-example/wandb
|
||||
# /yolov7-tracker-example/info_SF.txt
|
||||
# /yolov7-tracker-example/400m.mp4
|
BIN
yolov7-tracker-example/400m.mp4
Normal file
@ -0,0 +1,156 @@
|
||||
# parameters
|
||||
nc: 1 # number of classes
|
||||
depth_multiple: 1.0 # model depth multiple
|
||||
width_multiple: 1.0 # layer channel multiple
|
||||
|
||||
# anchors
|
||||
anchors:
|
||||
- [15,37, 18,54, 22,54] # P3/8
|
||||
- [28,70, 28,85, 31,117] # P4/16
|
||||
- [38,119, 41,152, 60,186] # P5/32
|
||||
|
||||
# yolov7 backbone
|
||||
backbone:
|
||||
# [from, number, module, args]
|
||||
[[-1, 1, Conv, [40, 3, 1]], # 0
|
||||
|
||||
[-1, 1, Conv, [80, 3, 2]], # 1-P1/2
|
||||
[-1, 1, Conv, [80, 3, 1]],
|
||||
|
||||
[-1, 1, Conv, [160, 3, 2]], # 3-P2/4
|
||||
[-1, 1, Conv, [64, 1, 1]],
|
||||
[-2, 1, Conv, [64, 1, 1]],
|
||||
[-1, 1, Conv, [64, 3, 1]],
|
||||
[-1, 1, Conv, [64, 3, 1]],
|
||||
[-1, 1, Conv, [64, 3, 1]],
|
||||
[-1, 1, Conv, [64, 3, 1]],
|
||||
[-1, 1, Conv, [64, 3, 1]],
|
||||
[-1, 1, Conv, [64, 3, 1]],
|
||||
[[-1, -3, -5, -7, -8], 1, Concat, [1]],
|
||||
[-1, 1, Conv, [320, 1, 1]], # 13
|
||||
|
||||
[-1, 1, MP, []],
|
||||
[-1, 1, Conv, [160, 1, 1]],
|
||||
[-3, 1, Conv, [160, 1, 1]],
|
||||
[-1, 1, Conv, [160, 3, 2]],
|
||||
[[-1, -3], 1, Concat, [1]], # 18-P3/8
|
||||
[-1, 1, Conv, [128, 1, 1]],
|
||||
[-2, 1, Conv, [128, 1, 1]],
|
||||
[-1, 1, Conv, [128, 3, 1]],
|
||||
[-1, 1, Conv, [128, 3, 1]],
|
||||
[-1, 1, Conv, [128, 3, 1]],
|
||||
[-1, 1, Conv, [128, 3, 1]],
|
||||
[-1, 1, Conv, [128, 3, 1]],
|
||||
[-1, 1, Conv, [128, 3, 1]],
|
||||
[[-1, -3, -5, -7, -8], 1, Concat, [1]],
|
||||
[-1, 1, Conv, [640, 1, 1]], # 28
|
||||
|
||||
[-1, 1, MP, []],
|
||||
[-1, 1, Conv, [320, 1, 1]],
|
||||
[-3, 1, Conv, [320, 1, 1]],
|
||||
[-1, 1, Conv, [320, 3, 2]],
|
||||
[[-1, -3], 1, Concat, [1]], # 33-P4/16
|
||||
[-1, 1, Conv, [256, 1, 1]],
|
||||
[-2, 1, Conv, [256, 1, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[[-1, -3, -5, -7, -8], 1, Concat, [1]],
|
||||
[-1, 1, Conv, [1280, 1, 1]], # 43
|
||||
|
||||
[-1, 1, MP, []],
|
||||
[-1, 1, Conv, [640, 1, 1]],
|
||||
[-3, 1, Conv, [640, 1, 1]],
|
||||
[-1, 1, Conv, [640, 3, 2]],
|
||||
[[-1, -3], 1, Concat, [1]], # 48-P5/32
|
||||
[-1, 1, Conv, [256, 1, 1]],
|
||||
[-2, 1, Conv, [256, 1, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[[-1, -3, -5, -7, -8], 1, Concat, [1]],
|
||||
[-1, 1, Conv, [1280, 1, 1]], # 58
|
||||
]
|
||||
|
||||
# yolov7 head
|
||||
head:
|
||||
[[-1, 1, SPPCSPC, [640]], # 59
|
||||
|
||||
[-1, 1, Conv, [320, 1, 1]],
|
||||
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
|
||||
[43, 1, Conv, [320, 1, 1]], # route backbone P4
|
||||
[[-1, -2], 1, Concat, [1]],
|
||||
|
||||
[-1, 1, Conv, [256, 1, 1]],
|
||||
[-2, 1, Conv, [256, 1, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[[-1, -3, -5, -7, -8], 1, Concat, [1]],
|
||||
[-1, 1, Conv, [320, 1, 1]], # 73
|
||||
|
||||
[-1, 1, Conv, [160, 1, 1]],
|
||||
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
|
||||
[28, 1, Conv, [160, 1, 1]], # route backbone P3
|
||||
[[-1, -2], 1, Concat, [1]],
|
||||
|
||||
[-1, 1, Conv, [128, 1, 1]],
|
||||
[-2, 1, Conv, [128, 1, 1]],
|
||||
[-1, 1, Conv, [128, 3, 1]],
|
||||
[-1, 1, Conv, [128, 3, 1]],
|
||||
[-1, 1, Conv, [128, 3, 1]],
|
||||
[-1, 1, Conv, [128, 3, 1]],
|
||||
[-1, 1, Conv, [128, 3, 1]],
|
||||
[-1, 1, Conv, [128, 3, 1]],
|
||||
[[-1, -3, -5, -7, -8], 1, Concat, [1]],
|
||||
[-1, 1, Conv, [160, 1, 1]], # 87
|
||||
|
||||
[-1, 1, MP, []],
|
||||
[-1, 1, Conv, [160, 1, 1]],
|
||||
[-3, 1, Conv, [160, 1, 1]],
|
||||
[-1, 1, Conv, [160, 3, 2]],
|
||||
[[-1, -3, 73], 1, Concat, [1]],
|
||||
|
||||
[-1, 1, Conv, [256, 1, 1]],
|
||||
[-2, 1, Conv, [256, 1, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[-1, 1, Conv, [256, 3, 1]],
|
||||
[[-1, -3, -5, -7, -8], 1, Concat, [1]],
|
||||
[-1, 1, Conv, [320, 1, 1]], # 102
|
||||
|
||||
[-1, 1, MP, []],
|
||||
[-1, 1, Conv, [320, 1, 1]],
|
||||
[-3, 1, Conv, [320, 1, 1]],
|
||||
[-1, 1, Conv, [320, 3, 2]],
|
||||
[[-1, -3, 59], 1, Concat, [1]],
|
||||
|
||||
[-1, 1, Conv, [512, 1, 1]],
|
||||
[-2, 1, Conv, [512, 1, 1]],
|
||||
[-1, 1, Conv, [512, 3, 1]],
|
||||
[-1, 1, Conv, [512, 3, 1]],
|
||||
[-1, 1, Conv, [512, 3, 1]],
|
||||
[-1, 1, Conv, [512, 3, 1]],
|
||||
[-1, 1, Conv, [512, 3, 1]],
|
||||
[-1, 1, Conv, [512, 3, 1]],
|
||||
[[-1, -3, -5, -7, -8], 1, Concat, [1]],
|
||||
[-1, 1, Conv, [640, 1, 1]], # 117
|
||||
|
||||
[87, 1, Conv, [320, 3, 1]],
|
||||
[102, 1, Conv, [640, 3, 1]],
|
||||
[117, 1, Conv, [1280, 3, 1]],
|
||||
|
||||
[[118,119,120], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5)
|
||||
]
|
@ -0,0 +1,9 @@
|
||||
[[ 15. 37.]
|
||||
[ 18. 54.]
|
||||
[ 22. 54.]
|
||||
[ 28. 70.]
|
||||
[ 28. 85.]
|
||||
[ 31. 117.]
|
||||
[ 38. 119.]
|
||||
[ 41. 152.]
|
||||
[ 60. 186.]]
|
@ -0,0 +1,9 @@
|
||||
[[ 8. 19.]
|
||||
[ 9. 27.]
|
||||
[11. 27.]
|
||||
[14. 35.]
|
||||
[14. 44.]
|
||||
[16. 60.]
|
||||
[19. 60.]
|
||||
[21. 78.]
|
||||
[30. 94.]]
|
BIN
yolov7-tracker-example/data/dataset1_2024_06_19/boites.png
Normal file
After Width: | Height: | Size: 20 KiB |
@ -0,0 +1,126 @@
|
||||
import json
|
||||
import os, sys
|
||||
import math
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import seaborn as sns; sns.set() # for plot styling
|
||||
from PIL import Image
|
||||
|
||||
# os.chdir("/media/deniz/02B89600B895F301/BBD100K")
|
||||
# train_path = "data/labels/train/bdd100k_labels_images_train.json"
|
||||
#
|
||||
# with open(train_path,"r") as ftr:
|
||||
# trlabel = json.load(ftr)
|
||||
#
|
||||
# BBDlabeldict = {"bike":0,
|
||||
# "bus":1,
|
||||
# "car":2,
|
||||
# "motor":3,
|
||||
# "person":4,
|
||||
# "rider":5,
|
||||
# "traffic light":6,
|
||||
# "traffic sign":7,
|
||||
# "train":8,
|
||||
# "truck":9,
|
||||
# "drivable area":[],
|
||||
# "lane":[]}
|
||||
|
||||
# BBDlabeldict = {"bacterie":0}
|
||||
# imgsize = 256
|
||||
#
|
||||
# images_path = "data/bacteries/images/train_and_test1"
|
||||
# # images_path = "data/poulets/images/train_and_test1"
|
||||
|
||||
imgsize = int(input("Image size for train and run? "))
|
||||
print("=> imgsize =",imgsize)
|
||||
# imgsize = 256
|
||||
|
||||
BBDlabeldict = {"runner":0}
|
||||
|
||||
datasetpath = '/Users/noham/Documents/GitHub/Stage/2024/test/yolov7-tracker/data/dataset2fps/'
|
||||
images_path = datasetpath+"images"
|
||||
labels_path = datasetpath+"labels"
|
||||
|
||||
filenames = sorted(os.listdir(images_path))
|
||||
print("Nb d'images =",len(filenames))
|
||||
w,h = [] , []
|
||||
for i,file in enumerate(filenames):
|
||||
#print(file)
|
||||
try:
|
||||
# if True:
|
||||
im = Image.open(images_path+"/"+file)
|
||||
img_width = im.width
|
||||
img_height = im.height
|
||||
#print(img_width,img_height)
|
||||
fo = open(images_path.replace("images","labels")+"/"+file.replace("jpg","txt"), "r+")
|
||||
lines = fo.readlines()
|
||||
for line in lines:
|
||||
a = np.array(line.split(" ")).astype(float)
|
||||
w.append(a[3]*img_width)
|
||||
h.append(a[4]*img_height)
|
||||
if (a[3]*img_height<0.001) or (a[4]*img_height<0.001):
|
||||
print("!! ATTENTION : boite trop petite dans le fichier ",file, "=> il faut vérifier et supprimer la ligne dans le fichier label au format txt !!")
|
||||
except:
|
||||
pass
|
||||
w=np.asarray(w)#+0.001*(np.random.random((len(w),)) - 0.5)
|
||||
h=np.asarray(h)#+0.001*(np.random.random((len(w),)) - 0.5)
|
||||
print("h => min =",h.min()," max =",h.max())
|
||||
print("w => min =",w.min()," max =",h.max())
|
||||
print("Nb objets entourés =",len(h))
|
||||
|
||||
# sys.exit()
|
||||
# for ind1 in range(len(trlabel)):
|
||||
# for ind2 in range(len(trlabel[ind1]["labels"])):
|
||||
# try:
|
||||
# a=trlabel[ind1]["labels"][ind2]["box2d"] #traffic sign
|
||||
# x1,y1,x2,y2 = list(a.values())
|
||||
# width = abs(x1-x2)
|
||||
# height = abs(y1-y2)
|
||||
# w.append(width)
|
||||
# h.append(height)
|
||||
# except:
|
||||
# pass
|
||||
# w=np.asarray(w)
|
||||
# h=np.asarray(h)
|
||||
|
||||
x=[w,h]
|
||||
x=np.asarray(x)
|
||||
x=x.transpose()
|
||||
########################################## K- Means
|
||||
##########################################
|
||||
|
||||
from sklearn.cluster import KMeans
|
||||
kmeans3 = KMeans(n_clusters=9)
|
||||
kmeans3.fit(x)
|
||||
y_kmeans3 = kmeans3.predict(x)
|
||||
|
||||
##########################################
|
||||
centers3 = kmeans3.cluster_centers_
|
||||
|
||||
yolo_anchor_average=[]
|
||||
for ind in range (9):
|
||||
yolo_anchor_average.append(np.mean(x[y_kmeans3==ind],axis=0))
|
||||
|
||||
yolo_anchor_average=np.array(yolo_anchor_average)
|
||||
|
||||
plt.scatter(x[:, 0], x[:, 1], c=y_kmeans3, s=2, cmap='viridis')
|
||||
plt.scatter(yolo_anchor_average[:, 0], yolo_anchor_average[:, 1], c='red', s=50);
|
||||
yoloV3anchors = yolo_anchor_average
|
||||
yoloV3anchors[:, 0] =yolo_anchor_average[:, 0] /1920 *imgsize
|
||||
yoloV3anchors[:, 1] =yolo_anchor_average[:, 1] /1056 *imgsize
|
||||
yoloV3anchors = np.rint(yoloV3anchors)
|
||||
fig, ax = plt.subplots()
|
||||
for ind in range(9):
|
||||
rectangle= plt.Rectangle((0.5*imgsize-yoloV3anchors[ind,0]/2,0.5*imgsize-yoloV3anchors[ind,1]/2), yoloV3anchors[ind,0],yoloV3anchors[ind,1] , fc='b',edgecolor='b',fill = None)
|
||||
ax.add_patch(rectangle)
|
||||
ax.set_aspect(1.0)
|
||||
plt.axis([0,imgsize,0,imgsize])
|
||||
plt.savefig("boites.png",dpi=150)
|
||||
plt.show()
|
||||
|
||||
yoloV3anchors.sort(axis=0)
|
||||
print("Your custom anchor boxes are {}".format(yoloV3anchors))
|
||||
|
||||
F = open(datasetpath+"YOLOV_BDD_Anchors_"+str(imgsize)+".txt", "w")
|
||||
F.write("{}".format(yoloV3anchors))
|
||||
F.close()
|
@ -0,0 +1,4 @@
|
||||
train: data/dataset1_2024_06_19/liste_images.txt
|
||||
val: data/dataset1_2024_06_19/liste_images.txt
|
||||
nc: 1
|
||||
names: ['coureur']
|
After Width: | Height: | Size: 448 KiB |
After Width: | Height: | Size: 450 KiB |
After Width: | Height: | Size: 451 KiB |
After Width: | Height: | Size: 449 KiB |
After Width: | Height: | Size: 438 KiB |
After Width: | Height: | Size: 428 KiB |
After Width: | Height: | Size: 406 KiB |
After Width: | Height: | Size: 410 KiB |
After Width: | Height: | Size: 458 KiB |
After Width: | Height: | Size: 454 KiB |
After Width: | Height: | Size: 454 KiB |
After Width: | Height: | Size: 456 KiB |
After Width: | Height: | Size: 472 KiB |
After Width: | Height: | Size: 478 KiB |
After Width: | Height: | Size: 496 KiB |
After Width: | Height: | Size: 498 KiB |
After Width: | Height: | Size: 504 KiB |
After Width: | Height: | Size: 514 KiB |
After Width: | Height: | Size: 533 KiB |
After Width: | Height: | Size: 533 KiB |
After Width: | Height: | Size: 514 KiB |
After Width: | Height: | Size: 510 KiB |
After Width: | Height: | Size: 520 KiB |
After Width: | Height: | Size: 515 KiB |
After Width: | Height: | Size: 513 KiB |
After Width: | Height: | Size: 516 KiB |
After Width: | Height: | Size: 521 KiB |
After Width: | Height: | Size: 526 KiB |
After Width: | Height: | Size: 522 KiB |
After Width: | Height: | Size: 514 KiB |
After Width: | Height: | Size: 521 KiB |
After Width: | Height: | Size: 517 KiB |
After Width: | Height: | Size: 515 KiB |
After Width: | Height: | Size: 505 KiB |
After Width: | Height: | Size: 501 KiB |
After Width: | Height: | Size: 507 KiB |
After Width: | Height: | Size: 506 KiB |
After Width: | Height: | Size: 512 KiB |
After Width: | Height: | Size: 514 KiB |
After Width: | Height: | Size: 508 KiB |
After Width: | Height: | Size: 503 KiB |
After Width: | Height: | Size: 502 KiB |
After Width: | Height: | Size: 483 KiB |
After Width: | Height: | Size: 501 KiB |
After Width: | Height: | Size: 495 KiB |
After Width: | Height: | Size: 500 KiB |
After Width: | Height: | Size: 499 KiB |
After Width: | Height: | Size: 500 KiB |
After Width: | Height: | Size: 514 KiB |
After Width: | Height: | Size: 525 KiB |
After Width: | Height: | Size: 530 KiB |
After Width: | Height: | Size: 533 KiB |
After Width: | Height: | Size: 540 KiB |
After Width: | Height: | Size: 546 KiB |
After Width: | Height: | Size: 552 KiB |
After Width: | Height: | Size: 561 KiB |
After Width: | Height: | Size: 571 KiB |
After Width: | Height: | Size: 576 KiB |
After Width: | Height: | Size: 584 KiB |
After Width: | Height: | Size: 588 KiB |
After Width: | Height: | Size: 594 KiB |
After Width: | Height: | Size: 600 KiB |
After Width: | Height: | Size: 595 KiB |
After Width: | Height: | Size: 594 KiB |
After Width: | Height: | Size: 588 KiB |
After Width: | Height: | Size: 585 KiB |
After Width: | Height: | Size: 578 KiB |
After Width: | Height: | Size: 561 KiB |
After Width: | Height: | Size: 483 KiB |
After Width: | Height: | Size: 492 KiB |
After Width: | Height: | Size: 497 KiB |
After Width: | Height: | Size: 507 KiB |
After Width: | Height: | Size: 518 KiB |
After Width: | Height: | Size: 518 KiB |
After Width: | Height: | Size: 511 KiB |
After Width: | Height: | Size: 540 KiB |
After Width: | Height: | Size: 548 KiB |
After Width: | Height: | Size: 545 KiB |
After Width: | Height: | Size: 511 KiB |
After Width: | Height: | Size: 539 KiB |
After Width: | Height: | Size: 527 KiB |
After Width: | Height: | Size: 532 KiB |
After Width: | Height: | Size: 536 KiB |
After Width: | Height: | Size: 527 KiB |
After Width: | Height: | Size: 535 KiB |
After Width: | Height: | Size: 550 KiB |
After Width: | Height: | Size: 555 KiB |
After Width: | Height: | Size: 564 KiB |
After Width: | Height: | Size: 572 KiB |
After Width: | Height: | Size: 583 KiB |
After Width: | Height: | Size: 592 KiB |
After Width: | Height: | Size: 590 KiB |