<jupyter_start><jupyter_text>Running conv-netsThis ipython notebook walks you through the running_template.py script.First, we need to load the necessary python modules<jupyter_code>import h5py
import tifffile as tiff
from keras.backend.common import _UID_PREFIXES

from cnn_functions import nikon_getfiles, get_image, run_models_on_directory, get_image_sizes, segment_nuclei, segment_cytoplasm, dice_jaccard_indices
from model_zoo import sparse_bn_feature_net_61x61 as nuclear_fn

import os
import numpy as np
import scipy as sp
from scipy import ndimage
from scipy.misc import imsave<jupyter_output>Using Theano backend.
Using gpu device 0: Quadro K620 (CNMeM is disabled, cuDNN 5105)<jupyter_text>Next, we need to specify some directory locations - namely where the home data directory is (direc_name), where the raw images are located (data_location), where to store they cytoplasm prediction images (cyto_location), where to store the nuclear prediction images (nuclear_location), and where to store the final segmentation masks (mask_location)<jupyter_code>direc_name = './testing_data_allTogether/E2fNuclei/'
data_location = os.path.join(direc_name, 'RawImages')

nuclear_location = os.path.join(direc_name, 'Nuclear')
mask_location = os.path.join(direc_name, 'Masks')<jupyter_output><empty_output><jupyter_text>Next, we need to define the channel names. In this case, the cytoplasm network takes in phase and nuclear marker (far red) images. The channel names have to be present in the file names. We also need to specify the directory the conv-net parameter files live in and what the file names are.<jupyter_code>nuclear_channel_names = ['DAPI']

trained_network_nuclear_directory = "./trained_networks/E2fNuclei/"
nuclear_prefix = "2018-01-02_nuclei_all_61x61_bn_feature_net_61x61_"

#trained_network_nuclear_directory = "./trained_networks/"
#nuclear_prefix = "2016-07-12_nuclei_all_61x61_bn_feature_net_61x61_"<jupyter_output><empty_output><jupyter_text>Then, we normalize test data and save it in NormalizedRawData folder. We are using a network that takes in 61x61 images in this example. We need to manually feed in the window size (the number of pixels sampled around each pixels). We also need to specify the image size.<jupyter_code>win_nuclear = 30

image_size_x, image_size_y = get_image_sizes(data_location, nuclear_channel_names)<jupyter_output><empty_output><jupyter_text>Now we need to load the weights for the networks. Remember we make use of two networks - one for the cytoplasm and another for the nucleus. Because we use model parallelism, we have 5 networks for each segmentation task.<jupyter_code>list_of_nuclear_weights = []
for j in xrange(1):
	nuclear_weights = os.path.join(trained_network_nuclear_directory,  nuclear_prefix + str(j) + ".h5")
	list_of_nuclear_weights += [nuclear_weights]<jupyter_output><empty_output><jupyter_text>Next, we run all our networks on all the files in our directory.<jupyter_code>nuclear_predictions = run_models_on_directory(data_location, nuclear_channel_names, nuclear_location, model_fn = nuclear_fn, 
	list_of_weights = list_of_nuclear_weights, image_size_x = image_size_x, image_size_y = image_size_y, 
	win_x = win_nuclear, win_y = win_nuclear, split = False)<jupyter_output>Processing image 1 of 5
Processing image 2 of 5
Processing image 3 of 5<jupyter_text>Next, we need to refine the neural network predictions to create segmentation masks. The smoothing and num_iters parameters control the active contour refinement process.<jupyter_code>nuclear_masks = segment_nuclei(nuclear_predictions, mask_location = mask_location, threshold = 0.75, area_threshold = 100, solidity_threshold = 0.75, eccentricity_threshold = 0.95)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06410944206008584, 'fraction_numerical': 0.01984978540772532, 'mean_word_length': 6.967948717948718, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '343611', 'license': 'MIT', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1131, 'n_words': 371, 'path': '.ipynb_checkpoints/RunningConvnetsNuclei-checkpoint.ipynb', 'repo_name': 'vanvalen/deepcell-tf', 'size': '3728'}