Linux 서버에서 yolov7로 자신의 데이터 세트 훈련

머리말

yolov7은 저자가 블로그를 작성하기 전에 한동안 밖에 있었습니다. 이미 인터넷에는 그들의 논문의 혁신과 yolov7의 네트워크 구조를 설명하는 많은 블로그가 있습니다. 여기서는 자세히 설명하지 않겠습니다. 이 블로그는 주로 어떻게 yolov7을 사용하여 자신의 데이터 세트를 교육합니다.

환경 빌드

먼저 yolov7 공식 웹사이트[https://github.com/WongKinYiu/yolov7]에서 모든 프로젝트 코드를 다운로드한 다음 서버에 conda 가상 환경을 생성합니다.여기서는 python3.7 버전을 사용합니다.

	```
	conda create -n yolo7 python=3.7
	```

그런 다음 가상 환경을 활성화하고 yolov7-main 폴더에 들어가 다음 명령을 실행합니다.

	```
	pip install -r requirements.txt  -i https://pypi.tuna.tsinghua.edu.cn/simple/ 
	```

여기에서 Tsinghua University의 소스를 사용하여 Python의 해당 종속성 라이브러리를 설치하면 훨씬 빠를 것입니다.
설치 과정에서 오류가 없으면 이 환경을 직접 사용할 수 있습니다.설치 중에 패키지 설치 오류가 보고되는 경우 프로세스, 라인에 pip bag으로 다시 설치하십시오.

마지막으로 모델 학습을 위한 명령을 실행할 수 있으며 오류가 보고되지 않으면 환경이 완전히 설정된 것입니다.

	```
	python train.py --workers 8 --device 0 --batch-size 32 --data data/coco.yaml --img 640 640 --cfg cfg/training/yolov7.yaml --weights '' --name yolov7 --hyp data/hyp.scratch.p5.yaml
	```

구성 파일 수정

환경 설정을 기반으로 교육을 위해 자신의 데이터 세트를 사용하고 주로 자신의 데이터 세트에 레이블을 지정한 후 coco 데이터 형식으로 변환합니다(많은 온라인 자습서가 있으므로 여기에서 자세히 설명하지 않겠습니다). 준비한 데이터를 바탕으로 몇 가지 설정 파일만 수정하면 정상적으로 학습이 됩니다 저는 공식 데이터셋과 동일한 coco 데이터셋을 사용하고 있습니다 자체 데이터셋이라면 다음 사항에 주의하셔야 합니다 수정:
(1) cfg/training/yolov7.yaml에서 범주 수를 수정해야 합니다.

	```
	# parameters
	nc: 80  # number of classes  ##类别的数量需要进行修改
	depth_multiple: 1.0  # model depth multiple
	width_multiple: 1.0  # layer channel multiple
	```

(2) data/coco.yaml에서 읽은 데이터의 관련 정보를 수정해야 합니다.

	```	
# download command/URL (optional)
#download: bash ./scripts/get_coco.sh

# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: /data/benchmark/COCO2017/coco/train2017.txt  # 118287 images ## 需要修改
val: /data/benchmark/COCO2017/coco/val2017.txt  # 5000 images  ## 需要修改
test: /data/benchmark/COCO2017/coco/test-dev2017.txt  #    ## 需要修改

# number of classes
nc: 80    #需要修改

# class names 
names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
     'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
     'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
     'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
     'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
     'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
     'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
     'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
     'hair drier', 'toothbrush' ]   ##需要修改
	```

마침내

위 관련 내용을 수정한 후 모델 학습 명령을 직접 실행하여 모델을 학습시킬 수 있습니다.

저자는 single-card V100 batchsize를 32로 설정하여 yolov7을 총 300 epochs 동안 약 2주 정도 학습시켰습니다. 0.0065로 감소,
교육 손실 변환
obj_loss 약 0.024

트레이닝 세트에 대한 메트릭 추세 그래프는 대략 다음과 같습니다.
트레이닝 세트의 정확도 변환

추천

출처blog.csdn.net/weixin_42280271/article/details/127752851