coco label 얻기

ids = list(sorted(coco.imgs.keys()))
coco_idx = [ids[idx]]  # from index to coco_index
coco.loadAnns(self.coco.getAnnIds(coco_idx))

아래처럼 object별로 7개의 key값을 가짐

segmentation은 annotation type이 두개가있다.
segmentation1 : list[float], polygon 좌표 xy인데 flatten시켰다. 
segmentation2 :  a run-length-encoded (RLE) bit mask 
    'counts' :
    'size'     :

area : 객체 안에 속한 pixel 수

iscrowd :  0 또는 1, 1이면 정확도 측정할 때 제외함 

image_id : 현재 객체가 속한 image의 index, 그래서 같은 이미지에 있는 객체들은 값이 같음. (82783: coco2014train)

bbox : bounding box 좌표, 좌상단xy wh로 구성되어있으며 normalizing 안되어있음

category_id : ojbect의 class index 총 80개며 1~90사이의 값을 가짐

id : 각 object에 대한 id인데 어떻게 라벨링 되는지는 모르겠음.

 

아 category_id가 좀 다를 것이다 0~79의 80개 class가 아니라 1~90으로 나온다. 몇개 삭제된 클래스가 있다. 아래 tuple써서 치환(?)하면 됨
(255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 255, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 255, 24, 25, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 255, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 255, 60, 255, 255, 61, 255, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 255, 73, 74, 75, 76, 77, 78, 79)

 

https://github.com/cocodataset/cocoapi/issues/184

https://github.com/facebookresearch/Detectron/issues/100

https://www.immersivelimit.com/tutorials/create-coco-annotations-from-scratch

https://www.youtube.com/watch?v=h6s61a_pqfM 

 

'Deep Learning > 기타' 카테고리의 다른 글

vscode에서 서버 연결할 때, XHR failed  (0) 2021.08.26
Darknet validationset 학습 포함 여부  (0) 2021.07.29

 

링크 : darknet pretrained weights with MS-COCO detection dataset

틈틈히 작업하던 yolo to pytorch가 완성단계라 위 링크 weights들의 정확도를 재생산하는 것을 통해 검증하려고 하는데 validationset에 대한 결과가 이상하리만큼 높게 나오는 것을 발견했다.

yolov4 같은 겨우 width=608 height=608 in cfg: 65.7% mAP@0.5 (43.5% AP@0.5:0.95)  라고 적혀 있는데 (testset기준) 

coco 2017 validationset(5k)로 직접 evaluation 했더니

 Average Precision  (AP) @[ IoU=0.50:0.95 | area=   all | maxDets=100 ] = 0.500
 Average Precision  (AP) @[ IoU=0.50       | area=   all | maxDets=100 ] = 0.741

 

이 나왔다. 위 결과는 testset(40k)일테니 낮은건 이해하지만 유난히 높게 나왔다는 생각이 들어 조금 알아봤다.

 

왜 유난히 높다라는 생각이 들었냐면, 후속논문인 sclaed yolov4 에서 validationset을 통해 측정을 한 결과가 다음과 같다. yolov4-P5경우 896x896 이미지를 사용했는데 51.7 / 70.3 (아래 테이블 참조)이다. 따라서 위에서 yolov4로 돌린 결과가 이상하다고 볼 수 있다. 

 

첫번째로 yolov4를 학습할 때, validationset이 포함됐나?를 떠올렸다. 그러면 높은 결과가 이해가 되니까.

그러나 darknet 위키를 찾은결과 학습에는 분명히 validation 5k를 제외하고 학습이 되었다. 정말 이상해서 더 자료를 찾다가 원하는 내용의 issue를 찾았다.

The custom splits (trainvalno5k.txt and 5k.txt) for COCO 2014 are supposed to be the same as the default splits for COCO 2017 but they are not. This could explain why YOLOv4 does not produce the same validation results on both but a significantly better mAP on val2017. Also, this implies YOLO may be trained on a different training set compared with other object detectors. Then a direct comparison might not be fair. Any clarifications?

즉 coco2017과 darknet에서 쓰는 split (train, val, test)가 다르다. 이것은 trainset이 다르단 소리고 결과가 불공정하지않냐? 라는 질문이다.

그러면서 coco2014와 2017의 차이점도 친절하게 official에서 긁어놨다.

The only difference is the splits which COCO 2017 adopts as the long-ime convention from COCO 2014 in early object detection work. The detectron repo explicitly describes the COCO Minival Annotations (5k) as follows:

Our custom minival and valminusminival annotations are available for download here. Please note that minival is exactly equivalent to the recently defined 2017 val set. Similarly, the union of valminusminival and the 2014 train is exactly equivalent to the 2017 train set.

즉 2014와 2017은 이미지가 전혀 바뀐게 없고 split만 바꼈다는 것인데 다음과 같다. (valminusminival의 존재를 처음 앎;)

COCO_2017_train = COCO_2014_train + valminusminival 
COCO_2017_val = minival

거기에 대한 답은 이렇다.

- testset은 같다.
- validation이 다르지만 결국엔 똑같은 장수를 validation으로 뺐고 test는 같으니 결과는 문제없다!.
심지어 우리는 최종 weight에 5k를 빼고학습했으니 오히려 마이너스 요소가 될 수 있다. 가 답변이다.

왜 다른 split을 쓰는지는 나도 모르겠지만, test로 성능측정하려면 서버에 결과제출해야해서 귀찮은데..하 아무튼 이런 이슈가 존재한다. 

'Deep Learning > 기타' 카테고리의 다른 글

vscode에서 서버 연결할 때, XHR failed  (0) 2021.08.26
coco label items  (0) 2021.08.11

darknet은 하나의 딥러닝 framework로 볼 수 있는데, 대표적으로 darknet18,53등의 classification 모델을 포함한 yolov3 for detection등의 모델 등이 있다.
나는 pytorch를 주로 쓰는데, 위에 언급한 모델들은 darknet이라는 c++계열의 framework를 쓴다. 그래서 나는 이걸 파이토치로 옮겨오는 방법을 많이 고민했고 그 동안 고민했던 그 흔적들을 정리해보려고한다.
어.. cfg 파일이 뭐니 weight파일이 뭐니 이러한 기초적인 설명은 다 건너 뛸거다. 왜냐면 이글은 공유보다 내 개인적인 기록이 목적인 용도니까.
맨 처음은 당연히 cfg파일을 파싱하는 부분이다.
다크넷의; cfg파일을 보면 각 레이어는 '[' ']' 두 기호로 대표적인 역할을 구분하고 있고, 그 이후로 기타 세부적인 옵션들을 정의하고있다. 그래서 아래 코드는 cfg파일에서 [] 두 기호를 토대로 레이어를 구분하고, 그 옵션들은 저장하는 코드이다.

cfg conv layer 예시
def parse_cfg(self, cfgfile): ''' cfgfile : cfgfile path, e.g. ./cfg/yolov3.cfg return : list of blocks. each block describes a block in the neural network to be built. ''' print(f"parse from '{cfgfile}'") fp = open(cfgfile, 'r') lines = fp.readlines() fp.close() lines = [line.strip() for line in lines if line.strip()] # 공백 제거 lines = [line for line in lines if line[0] != '#'] # 주석 제거 blocks = [] block = {} for line in lines: if line[0] == '[': if block: blocks.append(block) block = {} block["type"] = line[1:-1] if block['type'] == 'convolutional': block['batch_normalize'] = 0 else: key, value = line.split('=') block[key.rstrip()] = value.lstrip() blocks.append(block) print("done", end="\n\n") return blocks[0], blocks[1:]

맨 마지막에 block0 과 그 이후를 구분하는 이유는 모든 다크넷 cfg는 맨처음에 [net]으로 미니배치가 얼마인지, 입력 height widht가 얼마인지등을 정의해놓는데 이것을 구분하기 위함이다.
self 키워드가 있는것을 보아 이미 클래스 내부 함수인 것을 알겠지만 사실 외부 함수로 짜도 그만이라, 아무튼

클래스 내에서 위처럼 짜면 1단계는 완성이다.
이 다음에는 저 block(list())를 통해서 어떻게 pytorch 에서 forwarding을 구성하는지를 구성하겠다.
늘 말하지만, 언제 업로드 될진 모른다.

'Deep Learning > pytorch' 카테고리의 다른 글

[pytorch] save pytorch model  (0) 2021.09.15
torch.backends.cudnn.benchmark = True 의미  (0) 2021.08.23

+ Recent posts