def mergecrop(self, run_shape, run_shape_b_index, bottom_a, bottom_b): run_shape_a = run_shape[-1] run_shape_b = run_shape[run_shape_b_index] # Shape update rules update = RunShapeUpdater() update.fmaps_update = lambda x: run_shape_a.fmaps + run_shape_b.fmaps self.update_shape(run_shape, update) return L.MergeCrop(bottom_a, bottom_b, forward=[1, 1], backward=[1, 1])
def mergecrop(run_shape, bottom_a, bottom_b): # Shape update rules update = [lambda x: 0, lambda x: 0, lambda x: 2 * x] update += [[lambda x: x, lambda x: x, lambda x: x]] update += [[lambda x, i=i: x for i in range(0, len(run_shape[-1][4]))]] update_shape(run_shape, update) return L.MergeCrop(bottom_a, bottom_b, forward=[1, 1], backward=[1, 1])
def mergecrop(self, run_shape, run_shape_b_index, bottom_a, bottom_b, op = 'stack'): run_shape_a = run_shape[-1] run_shape_b = run_shape[run_shape_b_index] # Shape update rules update = RunShapeUpdater() if (op == 'stack'): update.fmaps_update = lambda x: run_shape_a.fmaps + run_shape_b.fmaps else: update.fmaps_update = lambda x: run_shape_a.fmaps self.update_shape(run_shape, update) return L.MergeCrop(bottom_a, bottom_b, forward=[1,1], backward=[1,1], operation=(0 if (op == 'stack') else 1))
def mergecrop(bottom_a, bottom_b, op = 'stack'): return L.MergeCrop(bottom_a, bottom_b, forward=[1,1], backward=[1,1], operation=(0 if (op == 'stack') else 1))
def approximation(args): print('creating approximation...') # Start a network net = Unet3D.start(args) #UNET config net_depth = 3 net_width = 2 base_filters = 24 channels_in = 1 channels_out = base_filters # ReLU negative slope relu_slope = 0.005 strategy = [2, 2, 2] xs = [net.data] if args.nstreams > 1: xs = L.Split(net.data, ntop=args.nstreams) print('xs:', len(xs)) skip = [] # contracting part for d in range(net_depth): print('upsampling...', d) channels_out = base_filters * (3**d) x = Unet3D.vgg_block_approximation(args, xs, channels_in, channels_out) skip.append(x) # maxpool x = L.Pooling(x, pool=P.Pooling.MAX, kernel_size=strategy, stride=strategy, pad=[0], dilation=[1]) channels_in = channels_out xs = [x for _ in range(args.nstreams)] # bridge channels_out = base_filters * (3**net_depth) x = Unet3D.vgg_block_approximation(args, xs, channels_in, channels_out) # expanding channels_in = channels_out for d in reversed(range(net_depth)): print('downsampling...', d) x = L.Deconvolution(x, convolution_param=dict( num_output=channels_out, kernel_size=strategy, stride=strategy, pad=[0], group=1, dilation=[1], bias_term=False, weight_filler=dict(type='msra'), bias_filler=dict(type='constant'))) channels_out = base_filters * (3**(d)) x = L.Convolution(x, kernel_size=[1], stride=[1], dilation=[1], num_output=channels_out, pad=[0], param=[dict(lr_mult=1.0), dict(lr_mult=2.0)], weight_filler=dict(type='msra'), bias_filler=dict(type='constant')) x = L.MergeCrop(x, skip[d], forward=[1, 1], backward=[1, 1], operation=0) xs = [x for _ in range(args.nstreams)] x = Unet3D.vgg_block_approximation(args, xs, channels_in, channels_out) net = Unet3D.end(net, x) protonet = net.to_proto() protonet.name = 'net' # Store the network as prototxt with open(protonet.name + '.prototxt', 'w') as f: print(protonet, file=f)