Skip to content

Commit

Permalink
Fix test fail: Due to recompute_scale_factor missing in UpsamplingBil…
Browse files Browse the repository at this point in the history
…inear2d (#68)

* Fix test fail: Due to recompute_scale_factor missing in UpsamplingBilinear2d

* Add comments to explain the changes
  • Loading branch information
kingjuno authored Aug 3, 2022
1 parent 904f454 commit e3c4a1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions devolearn/cell_membrane_segmentor/cell_membrane_segmentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ def predict(self, image_path, pred_size = (350,250), centroid_mode = False):
im = cv2.imread(image_path,0)

tensor = self.preprocess(im)

# The model has issues with the latest PyTorch versions, which causes
# AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
# To avoid this, we manually set the recompute_scale_factor attribute to None
self.model.segmentation_head[1].recompute_scale_factor = None
res = self.model(tensor).detach().cpu().numpy()[0][0]

res = cv2.resize(res,pred_size)
Expand Down
6 changes: 6 additions & 0 deletions devolearn/cell_nucleus_segmentor/cell_nucleus_segmentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ def predict(self, image_path, pred_size = (350,250)):

im = cv2.imread(image_path,0)
tensor = self.preprocess(im)

# The model has issues with the latest PyTorch versions, which causes
# AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor'
# To avoid this, we manually set the recompute_scale_factor attribute to None
self.model.segmentation_head[1].recompute_scale_factor = None

res = self.model(tensor).detach().cpu().numpy()[0][0]
res = cv2.resize(res,pred_size)
return res

0 comments on commit e3c4a1c

Please sign in to comment.