Closed Divadi closed 4 years ago
There is not enough code. How did you register your dataset? If you're not using a coco-format dataset, you'll need to do this https://detectron2.readthedocs.io/tutorials/datasets.html#metadata-for-datasets to declare the class names.
Thank you for your response. I finally managed to get around this issue. It had cached everything into KITTI_train_coco_format.json in the outputs folder, and this wasn't being updated when I changed CATEGORIES in
MetadataCatalog.get("KITTI_" + d).set(thing_classes=CATEGORIES)
Is there a way to clear metadata (and the cached coco jsons)? I've been restarting my runtime instance to clear metadata.
That's indeed an issue we know but kind of live with it (discussed in https://github.com/facebookresearch/detectron2/pull/175#discussion_r340381085). cc @botcs maybe this can be improved, e.g. by a quick hash over all the dicts?
You can clear the cache by removing the output
directory. In fact, if you use the same directory it may also resume some other artifacts (e.g. append metrics to a previous run), so it's good to clean it.
Ah, I see. I'll do that for now then - thank you!
That's indeed an issue we know but kind of live with it (discussed in #175 (comment)). cc @botcs maybe this can be improved, e.g. by a quick hash over all the dicts?
You can clear the cache by removing the
output
directory. In fact, if you use the same directory it may also resume some other artifacts (e.g. append metrics to a previous run), so it's good to clean it.
Hmmm... what do you mean by a quick hash over all the dicts? A MetaData hash should be sufficient, otherwise the whole dataset_dicts
will be loaded just for verification, and it can heavily vary based on the dataset.
The main motive behind the hashing was to speed up the development by reducing the time that data fetching and conversion took. There was a warning thrown previously when fetching cached data, because yeah... it's not validated, but in return for the risk you don't have to wait e.g. 10 minute to just see what's going on in the extra layer you have added to the network.
One safe solution is to just pass False for the allow_cached
here argument while developing. Maybe that should be the default?
I agree that hashing the data is probably too expensive. I think at least https://github.com/facebookresearch/detectron2/blob/5d452a0ec0b8bc21e61c6cb4cfef34ef7fefdb90/detectron2/data/datasets/coco.py#L413 can be changed to a warning and instruct users that they should clean the cache if dataset is modified.
I'm slightly in favor of the safe option given that users are running into issues.
Thank you for your response. I finally managed to get around this issue. It had cached everything into KITTI_train_coco_format.json in the outputs folder, and this wasn't being updated when I changed CATEGORIES in
MetadataCatalog.get("KITTI_" + d).set(thing_classes=CATEGORIES)
Is there a way to clear metadata (and the cached coco jsons)? I've been restarting my runtime instance to clear metadata.
did you solve this? is there anything to do with cache?
Thank you for your response. I finally managed to get around this issue. It had cached everything into KITTI_train_coco_format.json in the outputs folder, and this wasn't being updated when I changed CATEGORIES in
MetadataCatalog.get("KITTI_" + d).set(thing_classes=CATEGORIES)
Is there a way to clear metadata (and the cached coco jsons)? I've been restarting my runtime instance to clear metadata.
did you solve this? is there anything to do with cache?
Hi @grmsljj, were you able to fix this? I am facing the same error too.
Facing the same error
@crsegerie Have you looked at #120. I was facing the same error too and was able to solve it this way
@ppwwyyxx , I need your urgent intervention here, I am completely confuse here.
assert len(class_names) == precisions.shape[2]
I have followed all the recommendation here but nothing works. I try to view the output of the coco_eval.eval and is:
{'params': <pycocotools.cocoeval.Params object at 0x7f1067d6f040>, 'counts': [10, 101, 0, 4, 5], 'date': '2024-06-11 06:13:34', 'precision': array([], shape=(10, 101, 0, 4, 5), dtype=float64), 'recall': array([], shape=(10, 0, 4, 5), dtype=float64), 'scores': array([], shape=(10, 101, 0, 4, 5), dtype=float64), 'ok_det_as_known': array([], shape=(10, 0, 4, 5), dtype=float64), 'unk_det_as_known': array([], shape=(10, 0, 4, 5), dtype=float64), 'tp_plus_fp_cs': array([], shape=(10, 101, 0, 4, 5), dtype=float64), 'fp_os': array([], shape=(10, 101, 0, 4, 5), dtype=float64)}
which indicate empty list for the precision, isn't that the model doesn't predict the classes?
After strenuous effort, I was able to resolve the problem. so for the benefit of others. I was using custom dataset which has a subtle annotation difference with the standard coco annotation. Obviously, these variations will have an impact in the coco evaluation functions.
cat_ids = sorted(coco_gt.getCatIds(catNms=known_names))
,
As for my case , accessing the the cat_ids by categories name failed because the category "name" in my json file is "name":"None", as indicated in the screenshot below:
Solution: I provided keys for cat_Ids instead of using the cat_Ids queries function from the coco api ` cat_ids = sorted(known_ids)
coco_eval.params.catIds = cat_ids`
Instructions To Reproduce the Issue:
git diff
) or what code you wrote I'm running COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml on a custom dataset (KITTI data). Training on three object types, and set the other 6 object types to "other" for 4 total classes.When I trained on all 9 classes without changing 6 of them to "other", I don't get an error.
cfg = get_cfg() cfg.merge_from_file(model_zoo.get_config_file("COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml")) cfg.DATASETS.TRAIN = ("KITTI_train",) cfg.DATASETS.TEST = () cfg.DATALOADER.NUM_WORKERS = 2 cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-Detection/faster_rcnn_R_50_FPN_3x.yaml") # Let training initialize from model zoo cfg.SOLVER.IMS_PER_BATCH = 2 cfg.SOLVER.BASE_LR = 0.005 cfg.SOLVER.MAX_ITER = 300 # 300 iterations seems good enough for this toy dataset; you may need to train longer for a practical dataset cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 128 # faster, and good enough for this toy dataset (default: 512) cfg.MODEL.ROI_HEADS.NUM_CLASSES = 4 #
os.makedirs(cfg.OUTPUT_DIR, exist_ok=True) trainer = DefaultTrainer(cfg) trainer.resume_or_load(resume=False) trainer.train()
from detectron2.evaluation import COCOEvaluator, inference_on_dataset from detectron2.data import build_detection_test_loader evaluator = COCOEvaluator("KITTI_train", cfg, False, output_dir="./output/") val_loader = build_detection_test_loader(cfg, "KITTI_train") inference_on_dataset(trainer.model, val_loader, evaluator)
another equivalent way is to use trainer.test
AssertionError Traceback (most recent call last)