Closed 15024287710Jackson closed 2 years ago
You've chosen to report an unexpected problem or bug. Unless you already know the root cause of it, please include details about it by filling the issue template. The following information is missing: "Instructions To Reproduce the Issue and Full Logs"; "Your Environment";
What are you using to label your images?
Dear, I just use the dataset called Fashionpedia, Here is Link : https://github.com/cvdfoundation/fashionpedia Some annotations of segmentation use polygon format, and the other annotations of segmentation use RLE format. I want know how I can transfer the RLE format to the polygon format.
Please show full log as the "Unexpected behaviors" issue template asked for.
@15024287710Jackson
I label my data with labelme, 'pip install labelme'.
For example, create a data folder, and in that folder create a test and train folder. Put your COCO JSON annotations in each folder alongside your images. Load the data with the code below. Make sure you specify your class names and change n to the number of classes that you have.
cfg.MODEL.ROI_HEADS.NUM_CLASSES = n
def get_data_dicts(directory, classes):
dataset_dicts = []
for filename in [file for file in os.listdir(directory) if file.endswith('.json')]:
json_file = os.path.join(directory, filename)
with open(json_file) as f:
img_anns = json.load(f)
record = {}
filename = os.path.join(directory, img_anns["imagePath"])
record["file_name"] = filename
annos = img_anns["shapes"]
record["height"] = img_anns["imageHeight"]
record["width"] = img_anns["imageWidth"]
objs = []
for anno in annos:
px = [a[0] for a in anno['points']] # x coord
py = [a[1] for a in anno['points']] # y-coord
poly = [(x, y) for x, y in zip(px, py)] # poly for segmentation
poly = [p for x in poly for p in x]
obj = {
"bbox": [np.min(px), np.min(py), np.max(px), np.max(py)],
"bbox_mode": BoxMode.XYXY_ABS,
"segmentation": [poly],
"category_id": classes.index(anno['label']),
"iscrowd": 0
}
objs.append(obj)
record["annotations"] = objs
dataset_dicts.append(record)
return dataset_dicts
classes = ["X", "X"]
data_path = "./XXXXX"
for d in ["train", "test"]:
DatasetCatalog.register(
"category_" + d,
lambda d=d: get_data_dicts(data_path+d, classes)
)
MetadataCatalog.get("category_" + d).set(thing_classes=classes)
microcontroller_metadata = MetadataCatalog.get("category_train")
Requested information was not provided in 7 days, so we're closing this issue.
Please open new issue if information becomes available. Otherwise, use github discussions for free-form discussions.
Dear ppwwyyxx,
I am sorry to reply your help so late.
Here is the full log about error.
[32m[09/17 13:12:22 d2.engine.train_loop]: [0mStarting training from iteration 0
[4m[5m[31mERROR[0m [32m[09/17 13:12:24 d2.engine.train_loop]: [0mException during training:
Traceback (most recent call last):
File "/root/autodl-tmp/code/detectron2/detectron2/engine/train_loop.py", line 149, in train
self.run_step()
File "/root/autodl-tmp/code/detectron2/detectron2/engine/defaults.py", line 494, in run_step
self._trainer.run_step()
File "/root/autodl-tmp/code/detectron2/detectron2/engine/train_loop.py", line 268, in run_step
data = next(self._data_loader_iter)
File "/root/autodl-tmp/code/detectron2/detectron2/data/common.py", line 234, in iter
for d in self.dataset:
File "/root/miniconda3/envs/detectronTwoEth/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 521, in next
data = self._next_data()
File "/root/miniconda3/envs/detectronTwoEth/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1203, in _next_data
return self._process_data(data)
File "/root/miniconda3/envs/detectronTwoEth/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1229, in _process_data
data.reraise()
File "/root/miniconda3/envs/detectronTwoEth/lib/python3.8/site-packages/torch/_utils.py", line 434, in reraise
raise exception
ValueError: Caught ValueError in DataLoader worker process 3.
Original Traceback (most recent call last):
File "/root/autodl-tmp/code/detectron2/detectron2/data/detection_utils.py", line 403, in annotations_to_instances
masks = PolygonMasks(segms)
File "/root/autodl-tmp/code/detectron2/detectron2/structures/masks.py", line 309, in init
self.polygons: List[List[np.ndarray]] = [
File "/root/autodl-tmp/code/detectron2/detectron2/structures/masks.py", line 310, in
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/root/miniconda3/envs/detectronTwoEth/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "/root/miniconda3/envs/detectronTwoEth/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 32, in fetch data.append(next(self.dataset_iter)) File "/root/autodl-tmp/code/detectron2/detectron2/data/common.py", line 201, in iter yield self.dataset[idx] File "/root/autodl-tmp/code/detectron2/detectron2/data/common.py", line 90, in getitem data = self._map_func(self._dataset[cur_idx]) File "/root/autodl-tmp/code/detectron2/detectron2/utils/serialize.py", line 26, in call return self._obj(*args, **kwargs) File "/root/autodl-tmp/code/detectron2/detectron2/data/dataset_mapper.py", line 189, in call self._transform_annotations(dataset_dict, transforms, image_shape) File "/root/autodl-tmp/code/detectron2/detectron2/data/dataset_mapper.py", line 131, in _transform_annotations instances = utils.annotations_to_instances( File "/root/autodl-tmp/code/detectron2/detectron2/data/detection_utils.py", line 405, in annotations_to_instances raise ValueError( ValueError: Failed to use mask_format=='polygon' from the given annotations!
[32m[09/17 13:12:24 d2.engine.hooks]: [0mTotal training time: 0:00:01 (0:00:00 on hooks)
[32m[09/17 13:12:24 d2.utils.events]: [0m iter: 0 lr: N/A max_mem: 375M
Traceback (most recent call last):
File "train_netPedia.py", line 172, in
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/root/miniconda3/envs/detectronTwoEth/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "/root/miniconda3/envs/detectronTwoEth/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 32, in fetch data.append(next(self.dataset_iter)) File "/root/autodl-tmp/code/detectron2/detectron2/data/common.py", line 201, in iter yield self.dataset[idx] File "/root/autodl-tmp/code/detectron2/detectron2/data/common.py", line 90, in getitem data = self._map_func(self._dataset[cur_idx]) File "/root/autodl-tmp/code/detectron2/detectron2/utils/serialize.py", line 26, in call return self._obj(*args, **kwargs) File "/root/autodl-tmp/code/detectron2/detectron2/data/dataset_mapper.py", line 189, in call self._transform_annotations(dataset_dict, transforms, image_shape) File "/root/autodl-tmp/code/detectron2/detectron2/data/dataset_mapper.py", line 131, in _transform_annotations instances = utils.annotations_to_instances( File "/root/autodl-tmp/code/detectron2/detectron2/data/detection_utils.py", line 405, in annotations_to_instances raise ValueError( ValueError: Failed to use mask_format=='polygon' from the given annotations!
Here is the setting in my train_netPedia which is the copy of train_net.
def setup(args): """ Create configs and perform basic setups. """ cfg = get_cfg() cfg.merge_from_file(args.config_file) cfg.merge_from_list(args.opts) cfg.MODEL.ROI_HEADS.NUM_CLASSES = 46 cfg.MODEL.SEM_SEG_HEAD.NUM_CLASSES = 46 cfg.MODEL.FCOS.NUM_CLASSES = 46 cfg.SOLVER.IMS_PER_BATCH = 7 cfg.DATALOADER.NUM_WORKERS = 5 cfg.MODEL.MASKIOU_ON = True ITERS_IN_ONE_EPOCH = int(80000 / 8) cfg.SOLVER.CHECKPOINT_PERIOD = ITERS_IN_ONE_EPOCH cfg.TEST.EVAL_PERIOD = ITERS_IN_ONE_EPOCH cfg.INPUT.MASK_FORMAT='bitmask' cfg.freeze() default_setup(cfg, args) return cfg
@ppwwyyxx
I copy the wrong setting for you.
I does not add cfg.INPUT.MASK_FORMAT='bitmask' when I train the model.
Detectron2 does not automatically turn RLE into polygons because there isn't an accurate implementation that can do this. If you must, https://github.com/facebookresearch/detectron2/blob/7c2c8fb168a2093ce06a531c1208fba48d2984ec/detectron2/utils/visualizer.py#L119-L136 this function can be a reference so you can do the conversion yourself. But it's inaccurate.
If your input contains RLE annotations it's recommended to use MASK_FORMAT='bitmask'
.
File "/root/miniconda3/envs/detectronTwoEth/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop data = fetcher.fetch(index) File "/root/miniconda3/envs/detectronTwoEth/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 32, in fetch data.append(next(self.dataset_iter)) File "/root/autodl-tmp/code/detectron2/detectron2/data/common.py", line 201, in iter yield self.dataset[idx] File "/root/autodl-tmp/code/detectron2/detectron2/data/common.py", line 90, in getitem data = self._map_func(self._dataset[cur_idx]) File "/root/autodl-tmp/code/detectron2/detectron2/utils/serialize.py", line 26, in call return self._obj(*args, **kwargs) File "/root/autodl-tmp/code/detectron2/detectron2/data/dataset_mapper.py", line 189, in call self._transform_annotations(dataset_dict, transforms, image_shape) File "/root/autodl-tmp/code/detectron2/detectron2/data/dataset_mapper.py", line 131, in _transform_annotations instances = utils.annotations_to_instances( File "/root/autodl-tmp/code/detectron2/detectron2/data/detection_utils.py", line 405, in annotations_to_instances raise ValueError( ValueError: Failed to use mask_format=='polygon' from the given annotations!
When I train with Fashionpedia whose segmentation is birmask, I do not how to solve the problem.
Can someone help me ?