pytorch-YOLOv4
pytorch-YOLOv4 copied to clipboard
NotImplementedError: Create your own 'get_image_id' function
Traceback (most recent call last):
File "train.py", line 626, in
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_id
s are in one-one correspondence.
There are already image_id
s 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)
I met the same problem. Do you solve it?
I met the same problem. Do you solve it?
you can see my pull request on this project.
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 I have sovled it,thanks.
for the func of 'get_image_id', My understanding is that you need to find a unique ID for how the image is named
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