Please Help! I am having an issue with my code on google colab #5044
Unanswered
christopherbrunswick
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
[Hi all, I am doing a instance segmentation project on google colab with detectron2 for my LAST course. I am having some confusion
with my code. I performed my annotations is VIA2 and exported them in json COCO format. I parsed the json file to scrape all the info
needed to register my dataset with detectron2 for training. The dataset that i'm accessing is my training dataset with 44 training images. When annotating I took out 3 images that were just terrible and not worth my time to annotate. So when running the function you should get 41 image ids. The function is only outputting the last instance in the dataset_dict as seen below. I'm not sure if there is an indentation problem or if functions just normally out put the last instance in a list or set. That's problem #1. This code is an adjustment to alot of the demo code that is seen online when performing instance or object segmentation. Since i'm only able to get one instance out of this function i'm only able to visualize 1 image using the code at the very bottom. This visualizing code is adjusted as well to show the one instance the function printed out. The issue here is that my annotation is not shown on the image and i know for a fact i annotated this image because all the images in the json file are annotated. That's problem #2. I'm confused here and really need someone to look at my code, please. Again, the problems are: why is my function only outputing the last instance in the dictionary instance (41) and why aren't my annotations showing when I visualize the registered dataset.
``
def get_annotations(dataset_directory, task):
Output:
[{'annotations': None,
'file_name': '/content/drive/MyDrive/instance_segmentation/Detectron2/datasets/train/50389910431_2fa3bd64b8_e.jpg',
'height': 333,
'image_id': 41,
'width': 499}]
Registering dataset:
dataset = "/content/drive/MyDrive/instance_segmentation/Detectron2/datasets"
for d in ["train", "val"]:
DatasetCatalog.register("goat_" + d, lambda d=d: get_annotations(f"{dataset}/{d}"))
MetadataCatalog.get("goat_" + d).set(thing_classes=["Goat"])
goat_data_metadata = MetadataCatalog.get("goat_train")
Visualizing:
dataset_dicts = get_annotations(dataset, "train")
for d in dataset_dicts:
img = cv2.imread(d["file_name"])
visualizer = Visualizer(img[:, :, ::-1], metadata=goat_data_metadata, scale=0.5)
out = visualizer.draw_dataset_dict(d)
plt.figure(figsize=(5,5))
plt.imshow(out.get_image()[:, :, ::-1][..., ::-1])
Beta Was this translation helpful? Give feedback.
All reactions