Esempio n. 1
0
 def predict_in_directory(self,
                          spath,
                          fold,
                          stage,
                          cb,
                          data,
                          limit=-1,
                          batchSize=32,
                          ttflips=False):
     with tqdm.tqdm(total=len(generic.dir_list(spath)),
                    unit="files",
                    desc="segmentation of images from " +
                    str(spath)) as pbar:
         for v in self.predict_on_directory(spath,
                                            fold=fold,
                                            stage=stage,
                                            limit=limit,
                                            batch_size=batchSize,
                                            ttflips=ttflips):
             b: imgaug.Batch = v
             for i in range(len(b.data)):
                 id = b.data[i]
                 entry = self.toEntry(b, i)
                 cb(id, entry, data)
             pbar.update(batchSize)
 def predict_in_directory(self,
                          spath,
                          fold,
                          stage,
                          cb,
                          data,
                          limit=-1,
                          batchSize=32,
                          ttflips=False):
     with tqdm.tqdm(total=len(generic.dir_list(spath)),
                    unit="files",
                    desc="segmentation of images from " +
                    str(spath)) as pbar:
         for v in self.predict_on_directory(spath,
                                            fold=fold,
                                            stage=stage,
                                            limit=limit,
                                            batch_size=batchSize,
                                            ttflips=ttflips):
             b: imgaug.Batch = v
             for i in range(len(b.data)):
                 id = b.data[i]
                 orig = b.images[i]
                 map = b.segmentation_maps_aug[i]
                 scaledMap = imgaug.augmenters.Scale({
                     "height": orig.shape[0],
                     "width": orig.shape[1]
                 }).augment_segmentation_maps([map])
                 cb(id, scaledMap[0], data)
             pbar.update(batchSize)
Esempio n. 3
0
    def predict_to_directory(self,
                             spath,
                             tpath,
                             fold=0,
                             stage=0,
                             limit=-1,
                             batchSize=32,
                             binaryArray=False,
                             ttflips=False):
        generic.ensure(tpath)
        with tqdm.tqdm(total=len(generic.dir_list(spath)),
                       unit="files",
                       desc="segmentation of images from " + str(spath) +
                       " to " + str(tpath)) as pbar:
            for v in self.predict_on_directory(spath,
                                               fold=fold,
                                               stage=stage,
                                               limit=limit,
                                               batch_size=batchSize,
                                               ttflips=ttflips):
                b: imgaug.Batch = v
                for i in range(len(b.data)):
                    id = b.data[i]
                    entry = self.toEntry(b, i)
                    if isinstance(tpath, datasets.ConstrainedDirectory):
                        tp = tpath.path
                    else:
                        tp = tpath
                    p = os.path.join(tp, id[0:id.index('.')] + ".npy")
                    save(p, entry)

                pbar.update(batchSize)
 def predict_to_directory(self,
                          spath,
                          tpath,
                          fold=0,
                          stage=0,
                          limit=-1,
                          batchSize=32,
                          binaryArray=False,
                          ttflips=False):
     generic.ensure(tpath)
     with tqdm.tqdm(total=len(generic.dir_list(spath)),
                    unit="files",
                    desc="segmentation of images from " + str(spath) +
                    " to " + str(tpath)) as pbar:
         for v in self.predict_on_directory(spath,
                                            fold=fold,
                                            stage=stage,
                                            limit=limit,
                                            batch_size=batchSize,
                                            ttflips=ttflips):
             b: imgaug.Batch = v
             for i in range(len(b.data)):
                 id = b.data[i]
                 orig = b.images[i]
                 map = b.segmentation_maps_aug[i]
                 scaledMap = imgaug.augmenters.Scale({
                     "height": orig.shape[0],
                     "width": orig.shape[1]
                 }).augment_segmentation_maps([map])
                 if isinstance(tpath, datasets.ConstrainedDirectory):
                     tp = tpath.path
                 else:
                     tp = tpath
                 if binaryArray:
                     np.save(os.path.join(tp, id[0:id.index('.')]),
                             scaledMap[0].arr)
                 else:
                     imageio.imwrite(
                         os.path.join(tp, id[0:id.index('.')] + ".png"),
                         (scaledMap[0].arr * 255).astype(np.uint8))
             pbar.update(batchSize)