Пример #1
0
 def predict(self, files, model_no, path=None, **kwargs):
     model_path = self.models[model_no]
     model = self.load_model(model_path)
     ds_kwargs = self.ds_kwargs
     # Adding extra padding (overlap) for models that have the same input and output shape
     if ds_kwargs['padding'][0] == 0:
         ds_kwargs['padding'] = (self.extra_padding, ) * 2
     ds = TileDataset(files, **ds_kwargs)
     dls = DataLoaders.from_dsets(ds,
                                  batch_size=self.bs,
                                  after_batch=self.get_batch_tfms(),
                                  shuffle=False,
                                  drop_last=False,
                                  **self.dl_kwargs)
     if torch.cuda.is_available(): dls.cuda()
     learn = Learner(dls, model, loss_func=self.loss_fn)
     if self.mpt: learn.to_fp16()
     if path: path = path / f'model_{model_no}'
     return learn.predict_tiles(dl=dls.train, path=path, **kwargs)
Пример #2
0
 def predict(self, files, model_no, bs=None, **kwargs):
     bs = bs or self.bs
     model_path = self.models[model_no]
     model = self.load_model(model_path)
     batch_tfms = Normalize.from_stats(*self.stats)
     ds = TileDataset(files, **self.ds_kwargs)
     dls = DataLoaders.from_dsets(ds,
                                  batch_size=bs,
                                  after_batch=batch_tfms,
                                  shuffle=False,
                                  drop_last=False,
                                  num_workers=0)
     if torch.cuda.is_available(): dls.cuda(), model.cuda()
     learn = Learner(dls, model, loss_func=self.loss_fn)
     if self.mpt: learn.to_fp16()
     results = learn.predict_tiles(dl=dls.train, **kwargs)
     pth_tmp = self.path / '.tmp' / model_path.name
     save_tmp(pth_tmp, files, results)
     return results