Skip to content
Snippets Groups Projects
Commit 21bf6909 authored by Farzaneh Labbaf's avatar Farzaneh Labbaf
Browse files

Make launch NN completely independent from GUI

parent a4994d5a
No related branches found
No related tags found
No related merge requests found
...@@ -15,18 +15,35 @@ sys.path.append("./disk") ...@@ -15,18 +15,35 @@ sys.path.append("./disk")
#this file handles the interaction with the disk, so loading/saving images #this file handles the interaction with the disk, so loading/saving images
#and masks and it also runs the neural network. #and masks and it also runs the neural network.
from GUI_main import App
from segment import segment from segment import segment
import Reader as nd import Reader as nd
import argparse import argparse
import skimage import skimage
import neural_network as nn import neural_network as nn
def LaunchPrediction(im, is_pc, pretrained_weights=None):
"""It launches the neural neutwork on the current image and creates
an hdf file with the prediction for the time T and corresponding FOV.
"""
im = skimage.exposure.equalize_adapthist(im)
im = im*1.0;
pred = nn.prediction(im, is_pc, pretrained_weights)
return pred
def ThresholdPred(thvalue, pred):
"""Thresholds prediction with value"""
if thvalue == None:
thresholdedmask = nn.threshold(pred)
else:
thresholdedmask = nn.threshold(pred, thvalue)
return thresholdedmask
def LaunchInstanceSegmentation(reader, image_type, fov_indices=[0], time_value1=0, time_value2=0, thr_val=None, min_seed_dist=5, path_to_weights=None): def LaunchInstanceSegmentation(reader, image_type, fov_indices=[0], time_value1=0, time_value2=0, thr_val=None, min_seed_dist=5, path_to_weights=None):
""" """
""" """
# cannot have both path_to_weights and image_type supplied # cannot have both path_to_weights and image_type supplied
if (image_type is not None) and (path_to_weights is not None): if (image_type is not None) and (path_to_weights is not None):
print("image_type and path_to_weights cannot be both supplied.") print("image_type and path_to_weights cannot be both supplied.")
...@@ -58,7 +75,7 @@ def LaunchInstanceSegmentation(reader, image_type, fov_indices=[0], time_value1= ...@@ -58,7 +75,7 @@ def LaunchInstanceSegmentation(reader, image_type, fov_indices=[0], time_value1=
im = reader.LoadOneImage(t, fov_ind) im = reader.LoadOneImage(t, fov_ind)
try: try:
pred = App.LaunchPrediction(im, is_pc, pretrained_weights=path_to_weights) pred = LaunchPrediction(im, is_pc, pretrained_weights=path_to_weights)
except ValueError: except ValueError:
print('Error! ', print('Error! ',
'The neural network weight files could not ' 'The neural network weight files could not '
...@@ -67,7 +84,7 @@ def LaunchInstanceSegmentation(reader, image_type, fov_indices=[0], time_value1= ...@@ -67,7 +84,7 @@ def LaunchInstanceSegmentation(reader, image_type, fov_indices=[0], time_value1=
'the folder unet, or specify a path to a custom weights file with -w argument.') 'the folder unet, or specify a path to a custom weights file with -w argument.')
return return
thresh = App.ThresholdPred(thr_val, pred) thresh = ThresholdPred(thr_val, pred)
seg = segment(thresh, pred, min_seed_dist) seg = segment(thresh, pred, min_seed_dist)
reader.SaveMask(t, fov_ind, seg) reader.SaveMask(t, fov_ind, seg)
print('--------- Finished segmenting.') print('--------- Finished segmenting.')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment