11import multiprocessing as mp
22from abc import ABC
33from concurrent import futures
4+ from copy import deepcopy
45from typing import List , Optional
56
67import numpy as np
@@ -373,10 +374,12 @@ def generate(
373374 ):
374375 if not self .is_initialized :
375376 raise RuntimeError ("AutomaticMaskGenerator has not been initialized. Call initialize first." )
377+
376378 data = amg_utils .MaskData ()
377379 for data_ , crop_box in zip (self .crop_list , self .crop_boxes ):
378380 crop_data = self ._postprocess_batch (
379- data = data_ , crop_box = crop_box , original_size = self .original_size ,
381+ data = deepcopy (data_ ),
382+ crop_box = crop_box , original_size = self .original_size ,
380383 pred_iou_thresh = pred_iou_thresh ,
381384 stability_score_thresh = stability_score_thresh ,
382385 stability_score_offset = stability_score_offset ,
@@ -527,7 +530,8 @@ def generate(
527530 raise RuntimeError ("AutomaticMaskGenerator has not been initialized. Call initialize first." )
528531
529532 data = self ._postprocess_batch (
530- data = self .crop_list [0 ], crop_box = self .crop_boxes [0 ], original_size = self .original_size ,
533+ data = deepcopy (self .crop_list [0 ]), crop_box = self .crop_boxes [0 ],
534+ original_size = self .original_size ,
531535 pred_iou_thresh = pred_iou_thresh ,
532536 stability_score_thresh = stability_score_thresh ,
533537 stability_score_offset = stability_score_offset ,
@@ -541,12 +545,12 @@ def generate(
541545 def _resize_segmentation (self , segmentation , shape ):
542546 longest_size = max (shape )
543547 longest_shape = (longest_size , longest_size )
544- segmentation_ = resize (
548+ resized_segmentation = resize (
545549 segmentation , longest_shape , order = 0 , preserve_range = True , anti_aliasing = False
546550 ).astype (segmentation .dtype )
547551 crop = tuple (slice (0 , sh ) for sh in shape )
548- segmentation_ = segmentation_ [crop ]
549- return segmentation_
552+ resized_segmentation = resized_segmentation [crop ]
553+ return resized_segmentation
550554
551555 def get_initial_segmentation (self ):
552556 if not self .is_initialized :
@@ -667,7 +671,7 @@ def generate(
667671
668672 def segment_tile (_ , tile_id ):
669673 tile = tiling .getBlockWithHalo (tile_id , list (self ._halo )).outerBlock
670- mask_data = self ._crop_list [tile_id ]
674+ mask_data = deepcopy ( self ._crop_list [tile_id ])
671675 crop_box = self .crop_boxes [tile_id ]
672676 this_tile_shape = tuple (end - beg for beg , end in zip (tile .begin , tile .end ))
673677 mask_data = self ._postprocess_batch (
0 commit comments