def interp_upsampling(V): """ upsample a field by a factor of 2 TODO: should switch this to use neuron.utils.interpn() """ #print(V.shape) grid = nrn_utils.volshape_to_ndgrid( [f * 2 for f in V.get_shape().as_list()[1:-1]]) grid = [tf.cast(f, 'float32') for f in grid] grid = [tf.expand_dims(f / 2 - f, 0) for f in grid] offset = tf.stack(grid, len(grid) + 1) #xx = tf.cast(xx, 'float32') #yy = tf.cast(yy, 'float32') #zz = tf.cast(zz, 'float32') #xx = tf.expand_dims(xx/2-xx, 0) #yy = tf.expand_dims(yy/2-yy, 0) #zz = tf.expand_dims(zz/2-zz, 0) #print(xx.shape) #offset = tf.stack([xx, yy], 3) #print(offset.shape) #print(V.shape) # V = nrn_utils.transform(V, offset) V = nrn_layers.SpatialTransformer(interp_method='linear')([V, offset]) #print(V.shape) return V
def interp_upsampling(V): """ upsample a field by a factor of 2 TODO: should switch this to use neuron.utils.interpn() """ V = tf.reshape(V, [-1] + V.get_shape().as_list()[1:]) grid = volshape_to_ndgrid([f*2 for f in V.get_shape().as_list()[1:-1]]) grid = [tf.cast(f, 'float32') for f in grid] grid = [tf.expand_dims(f/2 - f, 0) for f in grid] offset = tf.stack(grid, len(grid) + 1) V = SpatialTransformer(interp_method='linear')([V, offset]) return V
def interp_upsampling(V): """ upsample a field by a factor of 2 TODO: should switch this to use neuron.utils.interpn() """ [xx, yy, zz] = nrn_utils.volshape_to_ndgrid([f*2 for f in V.get_shape().as_list()[1:4]]) xx = tf.cast(xx, 'float32') yy = tf.cast(yy, 'float32') zz = tf.cast(zz, 'float32') xx = tf.expand_dims(xx/2-xx, 0) yy = tf.expand_dims(yy/2-yy, 0) zz = tf.expand_dims(zz/2-zz, 0) offset = tf.stack([xx, yy, zz], 4) # V = nrn_utils.transform(V, offset) V = nrn_layers.SpatialTransformer(interp_method='linear')([V, offset]) return V