Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save pixelated masks to Tiled #172

Merged
merged 17 commits into from
Mar 6, 2024

Conversation

Wiebke
Copy link
Member

@Wiebke Wiebke commented Mar 4, 2024

This PR makes the following changes:

  • Introduces a new class TiledMaskHandler for handing mask loading and exporting calls. Currently this includes some legacy file-based code to be removed in the future.
  • With that new class, seperates data access into input data, masks, and segmentation results (all of which may live on different Tiled servers)
  • Pixelated masks are written to Tiled under MASK_TILED_URI + /USER_NAME/project_name/annotation_hash. This uri holds the meta data and an additional mask child contains the actual pixelated mask. This was original done to support writing annotations meta data for loading, without having to write pixelated masks. The writing happens upon job submission for model training.
  • To avoid writing the same mask again (e.g. if no changes have been made to the mask and the user only wants to run a different model), the key under which the mask is saved is a hash of the annotation meta-data (annotation classes with their names and colors, and annotation shapes)
  • Resolves Colormap for segmented results needs to respect user selections #169 by generating a color map from the current set of classes and colors. Note, if the number of classes changed between result writing and visualization, this can lead to inconsistencies. We may choose to instead use the metadata from writing masks in the future.
  • Adds a script examples/plot_mask.py to save a colored mask slice based on meta-data. This function could be used to generate a sample image for SciCat.

An example for mask meta data with two annotated slices containing some rectangles and a freeform is given below.

{
   "classes":{
      "0":{
         "color":"#004280",
         "label":"Background"
      },
      "1":{
         "color":"#ffae00",
         "label":"Clay"
      },
      "2":{
         "color":"#ff1900",
         "label":"Clay Anomaly"
      }
   },
   "data_uri":"https://tiled-seg.als.lbl.gov/api/v1/metadata/reconstruction/rec20190524_085542_clay_testZMQ_8bit/20190524_085542_clay_testZMQ_",
   "mask_idx":[
      "64",
      "222"
   ],
   "annotations":{
      "64":[
         {
            "type":"Rectangle",
            "class_id":"0",
            "svg_data":{
               "..."
            }
         },
         {
            "type":"Ellipse",
            "class_id":"1",
            "svg_data":{
               "..."
            }
         }
      ],
      "222":[
         {
            "type":"Closed Freeform",
            "class_id":"0",
            "svg_data":{
               "path":"..."
            }
         },
         {
            "type":"Rectangle",
            "class_id":"0",
            "svg_data":{
               "..."
            }
         },
         {
            "type":"Rectangle",
            "class_id":"1",
            "svg_data":{
               "..."
            }
         },
         {
            "type":"Rectangle",
            "class_id":"1",
            "svg_data":{
               "..."
            }
         },
         {
            "type":"Closed Freeform",
            "class_id":"2",
            "svg_data":{
               "path":"..."
            }
         }
      ]
   },
   "image_shape":[
      1760,
      1760
   ],
   "project_name":"rec20190524_085542_clay_testZMQ_8bit",
   "unlabeled_class_id":-1
}

with the second exported colored slice as

mask

This partially resolves #160, but annotation export still relies on files.

self.annotations = annotations
self.annotations_hash = self.get_annotations_hash()
self.image_shape = global_store["image_shapes"][0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using Safari as browser, I get an error in this line and in data_utils.py line 184. It seems like the key changes to 'active_img_shape': [1760, 1760]

@taxe10 taxe10 merged commit 555c27f into mlexchange:main Mar 6, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Colormap for segmented results needs to respect user selections Save and load masks
2 participants