提交 6d0af1ed 编写于 作者: 欲游山河十万里's avatar 欲游山河十万里

提交数据处理的代码

上级 76a76433
# coding:utf-8
import json
import os
import os.path
from PIL import Image
from tqdm import tqdm
def listPathAllfiles(dirname):
result = []
for maindir, subdir, file_name_list in os.walk(dirname):
for filename in file_name_list:
apath = os.path.join(maindir, filename)
result.append(apath)
return result
if __name__ == '__main__':
annos_path = r"E:\06服饰\Deepfashion2\train\train\annos" # 改成需要路径
image_path = r"E:\06服饰\Deepfashion2\train\train\images" # 改成需要路径
labels_path = r"E:\06服饰\Deepfashion2\train\train\labels" # 改成需要路径
num_images = len(os.listdir(annos_path))
for num in tqdm(range(1, num_images + 1)):
json_name = os.path.join(annos_path, str(num).zfill(6) + '.json')
image_name = os.path.join(image_path, str(num).zfill(6) + '.jpg')
txtfile = os.path.join(labels_path, str(num).zfill(6) + '.txt')
imag = Image.open(image_name)
width, height = imag.size
res = []
with open(json_name, 'r') as f:
temp = json.loads(f.read())
for i in temp:
if i == 'source' or i == 'pair_id':
continue
else:
box = temp[i]['bounding_box']
x_1 = round((box[0] + box[2]) / 2 / width, 6)
y_1 = round((box[1] + box[3]) / 2 / height, 6)
w = round((box[2] - box[0]) / width, 6)
h = round((box[3] - box[1]) / height, 6)
category_id = int(temp[i]['category_id'] - 1)
res.append(" ".join([str(category_id), str(x_1), str(y_1), str(w), str(h)]))
open(txtfile, "w").write("\n".join(res))
from ultralytics import RTDETR from ultralytics import RTDETR
from ultralytics import YOLO from ultralytics import YOLO
# Load a model # Load a model
model = RTDETR("E:/fourworkplace/yolov8v4/ultralytics/cfg/models/v8/yolov8-swinV2-RTVIT.yaml") # build a new model from scratch model = RTDETR("E:/fourworkplace/yolov8v4/ultralytics/cfg/models/v8/yolov8-swinV2-RTViT.yaml") # build a new model from scratch
model.info() model.info()
model1=RTDETR("E:/fourworkplace/yolov8v4/ultralytics/cfg/models/v8/yolov8-swinV2-RT.yaml") model1=RTDETR("E:/fourworkplace/yolov8v4/ultralytics/cfg/models/v8/yolov8-swinV2-RT.yaml")
...@@ -12,7 +12,8 @@ model2.info() ...@@ -12,7 +12,8 @@ model2.info()
model3=RTDETR("E:/fourworkplace/yolov8v4/ultralytics/cfg/models/v3/yolov3-swinV2-RTViT.yaml")
model3.info()
...@@ -35,5 +35,7 @@ model = YOLO("E:/fourworkplace/yolov8v4/ultralytics/cfg/models/v8/yolov8-swinV2- ...@@ -35,5 +35,7 @@ model = YOLO("E:/fourworkplace/yolov8v4/ultralytics/cfg/models/v8/yolov8-swinV2-
model.train(data="E:/fourworkplace/yolov8v4/ultralytics/cfg/datasets/yolov8_four.yaml", model.train(data="E:/fourworkplace/yolov8v4/ultralytics/cfg/datasets/yolov8_four.yaml",
pretrained=True,epochs=epoch_set,batch=64,patience=200,resume=True,workers=workers_set) pretrained=True,epochs=epoch_set,batch=64,patience=200,resume=True,workers=workers_set)
#使用YOLOv3进行训练,并把我们的改进方法加到YOLOv3上面以此突出改进方案的优势。
#下面开始考虑对图像分割问题的处理方案 #下面开始考虑对图像分割问题的处理方案
path: ../datasets/imagenet # dataset root dir
train: train # train images (relative to 'path') 1281167 images
val: val # val images (relative to 'path') 50000 images
test: # test images (optional)
nc: 13 # number of classes
names: ['short sleeve top', 'long sleeve top','short sleeve outwear','long sleeve outwear',
'vest','sling','shorts','trousers','skirt','short sleeve dress','long sleeve dress',
'vest dress','sling dress']
path: ../datasets/imagenet # dataset root dir
train: train # train images (relative to 'path') 1281167 images
val: val # val images (relative to 'path') 50000 images
test: # test images (optional)
nc: 13 # number of classes
names: [ 'short sleeve top', 'long sleeve top','short sleeve outwear','long sleeve outwear',
'vest','sling','shorts','trousers','skirt','short sleeve dress','long sleeve dress',
'vest dress','sling dress' ]
# Ultralytics YOLO 🚀, AGPL-3.0 license
# YOLOv3 object detection model with P3-P5 outputs. For details see https://docs.ultralytics.com/models/yolov3
# Parameters
nc: 13 # number of classes
depth_multiple: 1.0 # model depth multiple
width_multiple: 1.0 # layer channel multiple
# darknet53 backbone
backbone:
# [from, number, module, args]
[[-1, 1, Conv, [32, 3, 1]], # 0
[-1, 1, Conv, [64, 3, 2]], # 1-P1/2
[-1, 1, SwinV2_CSPB, [64]],
[-1, 1, Conv, [128, 3, 2]], # 3-P2/4
[-1, 2, SwinV2_CSPB, [128]],
[-1, 1, Conv, [256, 3, 2]], # 5-P3/8
[-1, 8, SwinV2_CSPB, [256]],
[-1, 1, Conv, [512, 3, 2]], # 7-P4/16
[-1, 8, SwinV2_CSPB, [512]],
[-1, 1, Conv, [1024, 3, 2]], # 9-P5/32
[-1, 4, SwinV2_CSPB, [1024]], # 10
]
# YOLOv3 head
head:
[[-1, 1, SwinV2_CSPB, [1024, False]],
[-1, 1, Conv, [512, 1, 1]],
[-1, 1, Conv, [1024, 3, 1]],
[-1, 1, Conv, [512, 1, 1]],
[-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large)
[-2, 1, Conv, [256, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 8], 1, Concat, [1]], # cat backbone P4
[-1, 1, SwinV2_CSPB, [512, False]],
[-1, 1, SwinV2_CSPB, [512, False]],
[-1, 1, Conv, [256, 1, 1]],
[-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium)
[-2, 1, Conv, [128, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 6], 1, Concat, [1]], # cat backbone P3
[-1, 1, SwinV2_CSPB, [256, False]],
[-1, 2, SwinV2_CSPB, [256, False]], # 27 (P3/8-small)
[[27, 22, 15], 1, RTDETRDecoderViT, [nc]], # Detect(P3, P4, P5)
]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册