Skip to content

Imports do not refresh images #630

@eric-fulfil

Description

@eric-fulfil

Hello and thanks for this awesome repo!

I noticed a bug where images would not display annotations after importing COCO JSON either through the UI or API. Diving into source I saw that the only way to trigger "generate_thumbnail" to be true was to hackily call the undocumented annotator/data endpoint:

    # Workaround for annotator not updating thumbnails upon import!
    def refresh_images(self, dataset, retries=10):
        dataset_id = dataset["id"]
        image_res = requests.get('http://localhost:5000/api/dataset/' + str(dataset_id) + "/coco",
            cookies=self.login_cookie,
            headers={
                'Content-Type': 'application/json',
            })
        images = image_res.json()
        if retries > 0 and len(images["images"]) == 0:
            time.sleep(1)
            return self.refresh_images(dataset, retries-1)
        
        # Query 1 more time now that indexing has begun
        time.sleep(5)
        image_res = requests.get('http://localhost:5000/api/dataset/' + str(dataset_id) + "/coco",
            cookies=self.login_cookie,
            headers={
                'Content-Type': 'application/json',
            })

        print("Redrawing " + str(len(images["images"])) + " labeled images")
        for img in images["images"]:
            inner = requests.post('http://localhost:5000/api/annotator/data',
                headers={
                    'Content-Type': 'application/json',
                },
                json={"dataset": dataset, "image": img},
                cookies=self.login_cookie)

I suppose simply flagging images annotated by the new import with that ImageRepo setter method would be a quick fix. I could probably open a PR if you'd like.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions