pytorch-YOLOv4 icon indicating copy to clipboard operation
pytorch-YOLOv4 copied to clipboard

NotImplementedError: Create your own 'get_image_id' function

Open yuxx0218 opened this issue 4 years ago • 7 comments

Traceback (most recent call last): File "train.py", line 626, in # device=device, ) File "train.py", line 425, in train evaluator = evaluate(eval_model, val_loader, config, device) File "/data/anaconda3/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 49, in decorate_no_grad return func(*args, **kwargs) File "train.py", line 471, in evaluate coco = convert_to_coco_api(data_loader.dataset, bbox_fmt='coco') File "/data/xxyu/code/pytorch-yolov4-master/tool/tv_reference/coco_utils.py", line 158, in convert_to_coco_api img, targets = ds[img_idx] File "/data/xxyu/code/pytorch-yolov4-master/dataset.py", line 271, in getitem return self._get_val_item(index) File "/data/xxyu/code/pytorch-yolov4-master/dataset.py", line 406, in _get_val_item target['image_id'] = torch.tensor([get_image_id(img_path)]) File "/data/xxyu/code/pytorch-yolov4-master/dataset.py", line 426, in get_image_id raise NotImplementedError("Create your own 'get_image_id' function") NotImplementedError: Create your own 'get_image_id' function

yuxx0218 avatar Aug 24 '20 07:08 yuxx0218

What is the point of the following function in dataset.py, which do nothing but only raise error.

def get_image_id(filename:str) -> int: """ Convert a string to a integer. Make sure that the images and the image_ids are in one-one correspondence. There are already image_ids in annotations of the COCO dataset, in which case this function is unnecessary. For creating one's own get_image_id function, one can refer to https://github.com/google/automl/blob/master/efficientdet/dataset/create_pascal_tfrecord.py#L86 or refer to the following code (where the filenames are like 'level1_123.jpg') >>> lv, no = os.path.splitext(os.path.basename(filename))[0].split("") >>> lv = lv.replace("level", "") >>> no = f"{int(no):04d}" >>> return int(lv+no) """ raise NotImplementedError("Create your own 'get_image_id' function") lv, no = os.path.splitext(os.path.basename(filename))[0].split("") lv = lv.replace("level", "") no = f"{int(no):04d}" return int(lv+no)

yuxx0218 avatar Aug 24 '20 08:08 yuxx0218

I met the same problem. Do you solve it?

bamboosdu avatar Aug 29 '20 09:08 bamboosdu

I met the same problem. Do you solve it?

you can see my pull request on this project.

yuxx0218 avatar Aug 31 '20 01:08 yuxx0218

Traceback (most recent call last): File "train.py", line 626, in

device=device, )

File "train.py", line 425, in train evaluator = evaluate(eval_model, val_loader, config, device) File "/data/anaconda3/lib/python3.7/site-packages/torch/autograd/grad_mode.py", line 49, in decorate_no_grad return func(*args, **kwargs) File "train.py", line 471, in evaluate coco = convert_to_coco_api(data_loader.dataset, bbox_fmt='coco') File "/data/xxyu/code/pytorch-yolov4-master/tool/tv_reference/coco_utils.py", line 158, in convert_to_coco_api img, targets = ds[img_idx] File "/data/xxyu/code/pytorch-yolov4-master/dataset.py", line 271, in getitem return self._get_val_item(index) File "/data/xxyu/code/pytorch-yolov4-master/dataset.py", line 406, in _get_val_item target['image_id'] = torch.tensor([get_image_id(img_path)]) File "/data/xxyu/code/pytorch-yolov4-master/dataset.py", line 426, in get_image_id raise NotImplementedError("Create your own 'get_image_id' function") NotImplementedError: Create your own 'get_image_id' function

This needs to modify the code according to the way of generating the labels of the dataset .The following is my dataset format and corresponding code modification:

labels: /home/pytorch-YOLOv4/data/VOC_2007/JPEGImages/500198.jpg 287.0,203.0,388.0,362.0,0

code:

def get_image_id(filename:str) -> int: print("You could also create your own 'get_image_id' function.") ##filename = "/home/123.jpg 11,34,56,78,0" parts = filename.split(' ') parts1 = parts[0].split('/') id = int(parts1[-1].split(".")[0]) return id this founction is to get the imagename (123), you can change the code according to your data labels

weilanShi avatar Sep 14 '20 08:09 weilanShi

@weilanShi I have sovled it,thanks.

zxj11838 avatar Sep 16 '20 07:09 zxj11838

for the func of 'get_image_id', My understanding is that you need to find a unique ID for how the image is named

LeBron-Jian avatar Apr 27 '21 08:04 LeBron-Jian

Used the following in my case:

def get_image_id(filename: str) -> int:
    """
    Convert a string to a integer....
    """
    _, no = os.path.splitext(os.path.basename(filename))[0].split("_")
    no = f"{int(no):04d}"
    return int(no)

My images looks like this: rgb_123.png

adrien-jacquot avatar Oct 01 '21 15:10 adrien-jacquot