annotate batchUNet2DtCycif.py @ 0:6bec4fef6b2e draft

"planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
author perssond
date Fri, 12 Mar 2021 00:17:29 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
1 import numpy as np
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
2 from scipy import misc
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
3 import tensorflow as tf
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
4 import shutil
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
5 import scipy.io as sio
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
6 import os,fnmatch,glob
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
7 import skimage.exposure as sk
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
8
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
9 import sys
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
10 sys.path.insert(0, 'C:\\Users\\Clarence\\Documents\\UNet code\\ImageScience')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
11 from toolbox.imtools import *
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
12 from toolbox.ftools import *
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
13 from toolbox.PartitionOfImage import PI2D
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
14
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
15
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
16 def concat3(lst):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
17 return tf.concat(lst,3)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
18
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
19 class UNet2D:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
20 hp = None # hyper-parameters
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
21 nn = None # network
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
22 tfTraining = None # if training or not (to handle batch norm)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
23 tfData = None # data placeholder
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
24 Session = None
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
25 DatasetMean = 0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
26 DatasetStDev = 0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
27
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
28 def setupWithHP(hp):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
29 UNet2D.setup(hp['imSize'],
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
30 hp['nChannels'],
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
31 hp['nClasses'],
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
32 hp['nOut0'],
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
33 hp['featMapsFact'],
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
34 hp['downSampFact'],
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
35 hp['ks'],
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
36 hp['nExtraConvs'],
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
37 hp['stdDev0'],
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
38 hp['nLayers'],
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
39 hp['batchSize'])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
40
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
41 def setup(imSize,nChannels,nClasses,nOut0,featMapsFact,downSampFact,kernelSize,nExtraConvs,stdDev0,nDownSampLayers,batchSize):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
42 UNet2D.hp = {'imSize':imSize,
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
43 'nClasses':nClasses,
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
44 'nChannels':nChannels,
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
45 'nExtraConvs':nExtraConvs,
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
46 'nLayers':nDownSampLayers,
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
47 'featMapsFact':featMapsFact,
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
48 'downSampFact':downSampFact,
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
49 'ks':kernelSize,
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
50 'nOut0':nOut0,
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
51 'stdDev0':stdDev0,
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
52 'batchSize':batchSize}
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
53
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
54 nOutX = [UNet2D.hp['nChannels'],UNet2D.hp['nOut0']]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
55 dsfX = []
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
56 for i in range(UNet2D.hp['nLayers']):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
57 nOutX.append(nOutX[-1]*UNet2D.hp['featMapsFact'])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
58 dsfX.append(UNet2D.hp['downSampFact'])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
59
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
60
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
61 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
62 # downsampling layer
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
63 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
64
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
65 with tf.name_scope('placeholders'):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
66 UNet2D.tfTraining = tf.placeholder(tf.bool, name='training')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
67 UNet2D.tfData = tf.placeholder("float", shape=[None,UNet2D.hp['imSize'],UNet2D.hp['imSize'],UNet2D.hp['nChannels']],name='data')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
68
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
69 def down_samp_layer(data,index):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
70 with tf.name_scope('ld%d' % index):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
71 ldXWeights1 = tf.Variable(tf.truncated_normal([UNet2D.hp['ks'], UNet2D.hp['ks'], nOutX[index], nOutX[index+1]], stddev=stdDev0),name='kernel1')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
72 ldXWeightsExtra = []
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
73 for i in range(nExtraConvs):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
74 ldXWeightsExtra.append(tf.Variable(tf.truncated_normal([UNet2D.hp['ks'], UNet2D.hp['ks'], nOutX[index+1], nOutX[index+1]], stddev=stdDev0),name='kernelExtra%d' % i))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
75
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
76 c00 = tf.nn.conv2d(data, ldXWeights1, strides=[1, 1, 1, 1], padding='SAME')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
77 for i in range(nExtraConvs):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
78 c00 = tf.nn.conv2d(tf.nn.relu(c00), ldXWeightsExtra[i], strides=[1, 1, 1, 1], padding='SAME')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
79
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
80 ldXWeightsShortcut = tf.Variable(tf.truncated_normal([1, 1, nOutX[index], nOutX[index+1]], stddev=stdDev0),name='shortcutWeights')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
81 shortcut = tf.nn.conv2d(data, ldXWeightsShortcut, strides=[1, 1, 1, 1], padding='SAME')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
82
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
83 bn = tf.layers.batch_normalization(tf.nn.relu(c00+shortcut), training=UNet2D.tfTraining)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
84
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
85 return tf.nn.max_pool(bn, ksize=[1, dsfX[index], dsfX[index], 1], strides=[1, dsfX[index], dsfX[index], 1], padding='SAME',name='maxpool')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
86
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
87 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
88 # bottom layer
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
89 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
90
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
91 with tf.name_scope('lb'):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
92 lbWeights1 = tf.Variable(tf.truncated_normal([UNet2D.hp['ks'], UNet2D.hp['ks'], nOutX[UNet2D.hp['nLayers']], nOutX[UNet2D.hp['nLayers']+1]], stddev=stdDev0),name='kernel1')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
93 def lb(hidden):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
94 return tf.nn.relu(tf.nn.conv2d(hidden, lbWeights1, strides=[1, 1, 1, 1], padding='SAME'),name='conv')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
95
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
96 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
97 # downsampling
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
98 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
99
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
100 with tf.name_scope('downsampling'):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
101 dsX = []
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
102 dsX.append(UNet2D.tfData)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
103
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
104 for i in range(UNet2D.hp['nLayers']):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
105 dsX.append(down_samp_layer(dsX[i],i))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
106
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
107 b = lb(dsX[UNet2D.hp['nLayers']])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
108
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
109 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
110 # upsampling layer
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
111 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
112
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
113 def up_samp_layer(data,index):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
114 with tf.name_scope('lu%d' % index):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
115 luXWeights1 = tf.Variable(tf.truncated_normal([UNet2D.hp['ks'], UNet2D.hp['ks'], nOutX[index+1], nOutX[index+2]], stddev=stdDev0),name='kernel1')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
116 luXWeights2 = tf.Variable(tf.truncated_normal([UNet2D.hp['ks'], UNet2D.hp['ks'], nOutX[index]+nOutX[index+1], nOutX[index+1]], stddev=stdDev0),name='kernel2')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
117 luXWeightsExtra = []
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
118 for i in range(nExtraConvs):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
119 luXWeightsExtra.append(tf.Variable(tf.truncated_normal([UNet2D.hp['ks'], UNet2D.hp['ks'], nOutX[index+1], nOutX[index+1]], stddev=stdDev0),name='kernel2Extra%d' % i))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
120
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
121 outSize = UNet2D.hp['imSize']
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
122 for i in range(index):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
123 outSize /= dsfX[i]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
124 outSize = int(outSize)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
125
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
126 outputShape = [UNet2D.hp['batchSize'],outSize,outSize,nOutX[index+1]]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
127 us = tf.nn.relu(tf.nn.conv2d_transpose(data, luXWeights1, outputShape, strides=[1, dsfX[index], dsfX[index], 1], padding='SAME'),name='conv1')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
128 cc = concat3([dsX[index],us])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
129 cv = tf.nn.relu(tf.nn.conv2d(cc, luXWeights2, strides=[1, 1, 1, 1], padding='SAME'),name='conv2')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
130 for i in range(nExtraConvs):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
131 cv = tf.nn.relu(tf.nn.conv2d(cv, luXWeightsExtra[i], strides=[1, 1, 1, 1], padding='SAME'),name='conv2Extra%d' % i)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
132 return cv
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
133
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
134 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
135 # final (top) layer
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
136 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
137
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
138 with tf.name_scope('lt'):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
139 ltWeights1 = tf.Variable(tf.truncated_normal([1, 1, nOutX[1], nClasses], stddev=stdDev0),name='kernel')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
140 def lt(hidden):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
141 return tf.nn.conv2d(hidden, ltWeights1, strides=[1, 1, 1, 1], padding='SAME',name='conv')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
142
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
143
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
144 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
145 # upsampling
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
146 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
147
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
148 with tf.name_scope('upsampling'):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
149 usX = []
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
150 usX.append(b)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
151
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
152 for i in range(UNet2D.hp['nLayers']):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
153 usX.append(up_samp_layer(usX[i],UNet2D.hp['nLayers']-1-i))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
154
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
155 t = lt(usX[UNet2D.hp['nLayers']])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
156
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
157
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
158 sm = tf.nn.softmax(t,-1)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
159 UNet2D.nn = sm
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
160
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
161
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
162 def train(imPath,logPath,modelPath,pmPath,nTrain,nValid,nTest,restoreVariables,nSteps,gpuIndex,testPMIndex):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
163 os.environ['CUDA_VISIBLE_DEVICES']= '%d' % gpuIndex
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
164
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
165 outLogPath = logPath
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
166 trainWriterPath = pathjoin(logPath,'Train')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
167 validWriterPath = pathjoin(logPath,'Valid')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
168 outModelPath = pathjoin(modelPath,'model.ckpt')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
169 outPMPath = pmPath
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
170
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
171 batchSize = UNet2D.hp['batchSize']
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
172 imSize = UNet2D.hp['imSize']
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
173 nChannels = UNet2D.hp['nChannels']
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
174 nClasses = UNet2D.hp['nClasses']
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
175
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
176 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
177 # data
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
178 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
179
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
180 Train = np.zeros((nTrain,imSize,imSize,nChannels))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
181 Valid = np.zeros((nValid,imSize,imSize,nChannels))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
182 Test = np.zeros((nTest,imSize,imSize,nChannels))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
183 LTrain = np.zeros((nTrain,imSize,imSize,nClasses))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
184 LValid = np.zeros((nValid,imSize,imSize,nClasses))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
185 LTest = np.zeros((nTest,imSize,imSize,nClasses))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
186
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
187 print('loading data, computing mean / st dev')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
188 if not os.path.exists(modelPath):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
189 os.makedirs(modelPath)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
190 if restoreVariables:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
191 datasetMean = loadData(pathjoin(modelPath,'datasetMean.data'))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
192 datasetStDev = loadData(pathjoin(modelPath,'datasetStDev.data'))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
193 else:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
194 datasetMean = 0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
195 datasetStDev = 0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
196 for iSample in range(nTrain+nValid+nTest):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
197 I = im2double(tifread('%s/I%05d_Img.tif' % (imPath,iSample)))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
198 datasetMean += np.mean(I)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
199 datasetStDev += np.std(I)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
200 datasetMean /= (nTrain+nValid+nTest)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
201 datasetStDev /= (nTrain+nValid+nTest)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
202 saveData(datasetMean, pathjoin(modelPath,'datasetMean.data'))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
203 saveData(datasetStDev, pathjoin(modelPath,'datasetStDev.data'))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
204
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
205 perm = np.arange(nTrain+nValid+nTest)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
206 np.random.shuffle(perm)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
207
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
208 for iSample in range(0, nTrain):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
209 path = '%s/I%05d_Img.tif' % (imPath,perm[iSample])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
210 im = im2double(tifread(path))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
211 Train[iSample,:,:,0] = (im-datasetMean)/datasetStDev
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
212 path = '%s/I%05d_Ant.tif' % (imPath,perm[iSample])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
213 im = tifread(path)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
214 for i in range(nClasses):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
215 LTrain[iSample,:,:,i] = (im == i+1)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
216
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
217 for iSample in range(0, nValid):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
218 path = '%s/I%05d_Img.tif' % (imPath,perm[nTrain+iSample])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
219 im = im2double(tifread(path))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
220 Valid[iSample,:,:,0] = (im-datasetMean)/datasetStDev
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
221 path = '%s/I%05d_Ant.tif' % (imPath,perm[nTrain+iSample])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
222 im = tifread(path)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
223 for i in range(nClasses):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
224 LValid[iSample,:,:,i] = (im == i+1)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
225
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
226 for iSample in range(0, nTest):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
227 path = '%s/I%05d_Img.tif' % (imPath,perm[nTrain+nValid+iSample])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
228 im = im2double(tifread(path))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
229 Test[iSample,:,:,0] = (im-datasetMean)/datasetStDev
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
230 path = '%s/I%05d_Ant.tif' % (imPath,perm[nTrain+nValid+iSample])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
231 im = tifread(path)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
232 for i in range(nClasses):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
233 LTest[iSample,:,:,i] = (im == i+1)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
234
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
235 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
236 # optimization
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
237 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
238
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
239 tfLabels = tf.placeholder("float", shape=[None,imSize,imSize,nClasses],name='labels')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
240
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
241 globalStep = tf.Variable(0,trainable=False)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
242 learningRate0 = 0.01
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
243 decaySteps = 1000
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
244 decayRate = 0.95
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
245 learningRate = tf.train.exponential_decay(learningRate0,globalStep,decaySteps,decayRate,staircase=True)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
246
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
247 with tf.name_scope('optim'):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
248 loss = tf.reduce_mean(-tf.reduce_sum(tf.multiply(tfLabels,tf.log(UNet2D.nn)),3))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
249 updateOps = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
250 # optimizer = tf.train.MomentumOptimizer(1e-3,0.9)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
251 optimizer = tf.train.MomentumOptimizer(learningRate,0.9)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
252 # optimizer = tf.train.GradientDescentOptimizer(learningRate)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
253 with tf.control_dependencies(updateOps):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
254 optOp = optimizer.minimize(loss,global_step=globalStep)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
255
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
256 with tf.name_scope('eval'):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
257 error = []
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
258 for iClass in range(nClasses):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
259 labels0 = tf.reshape(tf.to_int32(tf.slice(tfLabels,[0,0,0,iClass],[-1,-1,-1,1])),[batchSize,imSize,imSize])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
260 predict0 = tf.reshape(tf.to_int32(tf.equal(tf.argmax(UNet2D.nn,3),iClass)),[batchSize,imSize,imSize])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
261 correct = tf.multiply(labels0,predict0)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
262 nCorrect0 = tf.reduce_sum(correct)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
263 nLabels0 = tf.reduce_sum(labels0)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
264 error.append(1-tf.to_float(nCorrect0)/tf.to_float(nLabels0))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
265 errors = tf.tuple(error)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
266
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
267 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
268 # inspection
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
269 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
270
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
271 with tf.name_scope('scalars'):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
272 tf.summary.scalar('avg_cross_entropy', loss)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
273 for iClass in range(nClasses):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
274 tf.summary.scalar('avg_pixel_error_%d' % iClass, error[iClass])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
275 tf.summary.scalar('learning_rate', learningRate)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
276 with tf.name_scope('images'):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
277 split0 = tf.slice(UNet2D.nn,[0,0,0,0],[-1,-1,-1,1])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
278 split1 = tf.slice(UNet2D.nn,[0,0,0,1],[-1,-1,-1,1])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
279 if nClasses > 2:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
280 split2 = tf.slice(UNet2D.nn,[0,0,0,2],[-1,-1,-1,1])
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
281 tf.summary.image('pm0',split0)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
282 tf.summary.image('pm1',split1)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
283 if nClasses > 2:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
284 tf.summary.image('pm2',split2)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
285 merged = tf.summary.merge_all()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
286
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
287
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
288 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
289 # session
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
290 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
291
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
292 saver = tf.train.Saver()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
293 sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) # config parameter needed to save variables when using GPU
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
294
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
295 if os.path.exists(outLogPath):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
296 shutil.rmtree(outLogPath)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
297 trainWriter = tf.summary.FileWriter(trainWriterPath, sess.graph)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
298 validWriter = tf.summary.FileWriter(validWriterPath, sess.graph)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
299
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
300 if restoreVariables:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
301 saver.restore(sess, outModelPath)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
302 print("Model restored.")
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
303 else:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
304 sess.run(tf.global_variables_initializer())
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
305
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
306 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
307 # train
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
308 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
309
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
310 batchData = np.zeros((batchSize,imSize,imSize,nChannels))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
311 batchLabels = np.zeros((batchSize,imSize,imSize,nClasses))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
312 for i in range(nSteps):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
313 # train
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
314
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
315 perm = np.arange(nTrain)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
316 np.random.shuffle(perm)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
317
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
318 for j in range(batchSize):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
319 batchData[j,:,:,:] = Train[perm[j],:,:,:]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
320 batchLabels[j,:,:,:] = LTrain[perm[j],:,:,:]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
321
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
322 summary,_ = sess.run([merged,optOp],feed_dict={UNet2D.tfData: batchData, tfLabels: batchLabels, UNet2D.tfTraining: 1})
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
323 trainWriter.add_summary(summary, i)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
324
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
325 # validation
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
326
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
327 perm = np.arange(nValid)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
328 np.random.shuffle(perm)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
329
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
330 for j in range(batchSize):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
331 batchData[j,:,:,:] = Valid[perm[j],:,:,:]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
332 batchLabels[j,:,:,:] = LValid[perm[j],:,:,:]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
333
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
334 summary, es = sess.run([merged, errors],feed_dict={UNet2D.tfData: batchData, tfLabels: batchLabels, UNet2D.tfTraining: 0})
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
335 validWriter.add_summary(summary, i)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
336
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
337 e = np.mean(es)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
338 print('step %05d, e: %f' % (i,e))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
339
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
340 if i == 0:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
341 if restoreVariables:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
342 lowestError = e
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
343 else:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
344 lowestError = np.inf
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
345
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
346 if np.mod(i,100) == 0 and e < lowestError:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
347 lowestError = e
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
348 print("Model saved in file: %s" % saver.save(sess, outModelPath))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
349
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
350
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
351 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
352 # test
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
353 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
354
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
355 if not os.path.exists(outPMPath):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
356 os.makedirs(outPMPath)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
357
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
358 for i in range(nTest):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
359 j = np.mod(i,batchSize)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
360
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
361 batchData[j,:,:,:] = Test[i,:,:,:]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
362 batchLabels[j,:,:,:] = LTest[i,:,:,:]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
363
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
364 if j == batchSize-1 or i == nTest-1:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
365
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
366 output = sess.run(UNet2D.nn,feed_dict={UNet2D.tfData: batchData, tfLabels: batchLabels, UNet2D.tfTraining: 0})
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
367
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
368 for k in range(j+1):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
369 pm = output[k,:,:,testPMIndex]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
370 gt = batchLabels[k,:,:,testPMIndex]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
371 im = np.sqrt(normalize(batchData[k,:,:,0]))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
372 imwrite(np.uint8(255*np.concatenate((im,np.concatenate((pm,gt),axis=1)),axis=1)),'%s/I%05d.png' % (outPMPath,i-j+k+1))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
373
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
374
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
375 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
376 # save hyper-parameters, clean-up
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
377 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
378
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
379 saveData(UNet2D.hp,pathjoin(modelPath,'hp.data'))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
380
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
381 trainWriter.close()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
382 validWriter.close()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
383 sess.close()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
384
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
385 def deploy(imPath,nImages,modelPath,pmPath,gpuIndex,pmIndex):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
386 os.environ['CUDA_VISIBLE_DEVICES']= '%d' % gpuIndex
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
387
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
388 variablesPath = pathjoin(modelPath,'model.ckpt')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
389 outPMPath = pmPath
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
390
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
391 hp = loadData(pathjoin(modelPath,'hp.data'))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
392 UNet2D.setupWithHP(hp)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
393
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
394 batchSize = UNet2D.hp['batchSize']
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
395 imSize = UNet2D.hp['imSize']
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
396 nChannels = UNet2D.hp['nChannels']
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
397 nClasses = UNet2D.hp['nClasses']
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
398
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
399 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
400 # data
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
401 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
402
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
403 Data = np.zeros((nImages,imSize,imSize,nChannels))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
404
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
405 datasetMean = loadData(pathjoin(modelPath,'datasetMean.data'))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
406 datasetStDev = loadData(pathjoin(modelPath,'datasetStDev.data'))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
407
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
408 for iSample in range(0, nImages):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
409 path = '%s/I%05d_Img.tif' % (imPath,iSample)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
410 im = im2double(tifread(path))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
411 Data[iSample,:,:,0] = (im-datasetMean)/datasetStDev
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
412
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
413 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
414 # session
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
415 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
416
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
417 saver = tf.train.Saver()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
418 sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) # config parameter needed to save variables when using GPU
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
419
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
420 saver.restore(sess, variablesPath)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
421 print("Model restored.")
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
422
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
423 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
424 # deploy
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
425 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
426
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
427 batchData = np.zeros((batchSize,imSize,imSize,nChannels))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
428
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
429 if not os.path.exists(outPMPath):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
430 os.makedirs(outPMPath)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
431
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
432 for i in range(nImages):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
433 print(i,nImages)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
434
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
435 j = np.mod(i,batchSize)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
436
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
437 batchData[j,:,:,:] = Data[i,:,:,:]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
438
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
439 if j == batchSize-1 or i == nImages-1:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
440
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
441 output = sess.run(UNet2D.nn,feed_dict={UNet2D.tfData: batchData, UNet2D.tfTraining: 0})
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
442
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
443 for k in range(j+1):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
444 pm = output[k,:,:,pmIndex]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
445 im = np.sqrt(normalize(batchData[k,:,:,0]))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
446 # imwrite(np.uint8(255*np.concatenate((im,pm),axis=1)),'%s/I%05d.png' % (outPMPath,i-j+k+1))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
447 imwrite(np.uint8(255*im),'%s/I%05d_Im.png' % (outPMPath,i-j+k+1))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
448 imwrite(np.uint8(255*pm),'%s/I%05d_PM.png' % (outPMPath,i-j+k+1))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
449
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
450
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
451 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
452 # clean-up
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
453 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
454
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
455 sess.close()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
456
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
457 def singleImageInferenceSetup(modelPath,gpuIndex):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
458 #os.environ['CUDA_VISIBLE_DEVICES']= '%d' % gpuIndex
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
459
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
460 variablesPath = pathjoin(modelPath,'model.ckpt')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
461
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
462 hp = loadData(pathjoin(modelPath,'hp.data'))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
463 UNet2D.setupWithHP(hp)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
464
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
465 UNet2D.DatasetMean = loadData(pathjoin(modelPath,'datasetMean.data'))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
466 UNet2D.DatasetStDev = loadData(pathjoin(modelPath,'datasetStDev.data'))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
467 print(UNet2D.DatasetMean)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
468 print(UNet2D.DatasetStDev)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
469
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
470 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
471 # session
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
472 # --------------------------------------------------
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
473
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
474 saver = tf.train.Saver()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
475 UNet2D.Session = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) # config parameter needed to save variables when using GPU
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
476
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
477 saver.restore(UNet2D.Session, variablesPath)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
478 print("Model restored.")
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
479
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
480 def singleImageInferenceCleanup():
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
481 UNet2D.Session.close()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
482
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
483 def singleImageInference(image,mode,pmIndex):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
484 print('Inference...')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
485
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
486 batchSize = UNet2D.hp['batchSize']
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
487 imSize = UNet2D.hp['imSize']
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
488 nChannels = UNet2D.hp['nChannels']
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
489
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
490 PI2D.setup(image,imSize,int(imSize/8),mode)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
491 PI2D.createOutput(nChannels)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
492
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
493 batchData = np.zeros((batchSize,imSize,imSize,nChannels))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
494 for i in range(PI2D.NumPatches):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
495 j = np.mod(i,batchSize)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
496 batchData[j,:,:,0] = (PI2D.getPatch(i)-UNet2D.DatasetMean)/UNet2D.DatasetStDev
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
497 if j == batchSize-1 or i == PI2D.NumPatches-1:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
498 output = UNet2D.Session.run(UNet2D.nn,feed_dict={UNet2D.tfData: batchData, UNet2D.tfTraining: 0})
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
499 for k in range(j+1):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
500 pm = output[k,:,:,pmIndex]
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
501 PI2D.patchOutput(i-j+k,pm)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
502 # PI2D.patchOutput(i-j+k,normalize(imgradmag(PI2D.getPatch(i-j+k),1)))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
503
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
504 return PI2D.getValidOutput()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
505
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
506
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
507 if __name__ == '__main__':
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
508 logPath = 'C://Users//Clarence//Documents//UNet code//TFLogs'
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
509 modelPath = 'D:\\LSP\\UNet\\tonsil20x1bin1chan\\TFModel - 3class 16 kernels 5ks 2 layers'
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
510 pmPath = 'C://Users//Clarence//Documents//UNet code//TFProbMaps'
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
511
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
512
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
513
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
514 UNet2D.singleImageInferenceSetup(modelPath, 0)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
515 imagePath = 'D:\\LSP\\cycif\\testsets'
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
516 sampleList = glob.glob(imagePath + '//exemplar-001*')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
517 dapiChannel = 0
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
518 dsFactor = 1
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
519 for iSample in sampleList:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
520 fileList = glob.glob(iSample + '//registration//*.tif')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
521 print(fileList)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
522 for iFile in fileList:
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
523 fileName = os.path.basename(iFile)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
524 fileNamePrefix = fileName.split(os.extsep, 1)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
525 I = tifffile.imread(iFile, key=dapiChannel)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
526 rawI = I
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
527 hsize = int((float(I.shape[0])*float(dsFactor)))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
528 vsize = int((float(I.shape[1])*float(dsFactor)))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
529 I = resize(I,(hsize,vsize))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
530 I = im2double(sk.rescale_intensity(I, in_range=(np.min(I), np.max(I)), out_range=(0, 0.983)))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
531 rawI = im2double(rawI)/np.max(im2double(rawI))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
532 outputPath = iSample + '//prob_maps'
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
533 if not os.path.exists(outputPath):
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
534 os.makedirs(outputPath)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
535 K = np.zeros((2,rawI.shape[0],rawI.shape[1]))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
536 contours = UNet2D.singleImageInference(I,'accumulate',1)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
537 hsize = int((float(I.shape[0]) * float(1/dsFactor)))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
538 vsize = int((float(I.shape[1]) * float(1/dsFactor)))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
539 contours = resize(contours, (rawI.shape[0], rawI.shape[1]))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
540 K[1,:,:] = rawI
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
541 K[0,:,:] = contours
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
542 tifwrite(np.uint8(255 * K),
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
543 outputPath + '//' + fileNamePrefix[0] + '_ContoursPM_' + str(dapiChannel + 1) + '.tif')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
544 del K
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
545 K = np.zeros((1, rawI.shape[0], rawI.shape[1]))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
546 nuclei = UNet2D.singleImageInference(I,'accumulate',2)
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
547 nuclei = resize(nuclei, (rawI.shape[0], rawI.shape[1]))
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
548 K[0, :, :] = nuclei
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
549 tifwrite(np.uint8(255 * K),
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
550 outputPath + '//' + fileNamePrefix[0] + '_NucleiPM_' + str(dapiChannel + 1) + '.tif')
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
551 del K
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
552 UNet2D.singleImageInferenceCleanup()
6bec4fef6b2e "planemo upload for repository https://github.com/ohsu-comp-bio/unmicst commit 73e4cae15f2d7cdc86719e77470eb00af4b6ebb7-dirty"
perssond
parents:
diff changeset
553