def build_model(l_in=None): l_in = nn.layers.InputLayer(( None, p_transform['channels'], ) + p_transform['patch_size']) if l_in is None else l_in l_target = nn.layers.InputLayer((None, p_transform['n_labels'])) l_feat_cube = build_densenet(l_in, input_var=None, first_output=64, growth_rate=32, num_blocks=4, dropout=0) l_d = drop(l_feat_cube) l_feat = GlobalPoolLayer(l_d, name='post_pool') l = nn.layers.DenseLayer(l_feat, num_units=p_transform['n_labels'], W=nn.init.HeNormal(gain=1), nonlinearity=nn.nonlinearities.identity) l_weather = nn.layers.SliceLayer(l, indices=slice(0, 4), axis=-1) l_weather = nn.layers.NonlinearityLayer( l_weather, nonlinearity=nn.nonlinearities.softmax) l_other = nn_planet.MajorExclusivityLayer(l, idx_major=0) l_other = nn.layers.SliceLayer(l_other, indices=slice(4, None), axis=-1) l_out = nn.layers.ConcatLayer([l_weather, l_other], axis=-1) return namedtuple('Model', ['l_in', 'l_out', 'l_target', 'l_feat'])(l_in, l_out, l_target, l_feat)
def build_model(l_in=None): l_in = nn.layers.InputLayer((None, p_transform['channels'],) + p_transform['patch_size']) if l_in is None else l_in l_target = nn.layers.InputLayer((None,p_transform['n_labels'])) l = conv(l_in, 64) l = inrn_v2_red(l) l = inrn_v2(l) l = inrn_v2_red(l) l = inrn_v2(l) l = inrn_v2_red(l) l = inrn_v2(l) l = inrn_v2_red(l) l = inrn_v2(l) l = inrn_v2_red(l) l = inrn_v2(l) l_1q = nn.layers.SliceLayer(l, indices=slice(0,l.output_shape[1]/4), axis=1) l_2q = nn.layers.SliceLayer(l, indices=slice(l.output_shape[1]/4,l.output_shape[1]/2),axis=1) l_3q = nn.layers.SliceLayer(l, indices=slice(l.output_shape[1]/2,l.output_shape[1]*3/4),axis=1) l_4q = nn.layers.SliceLayer(l, indices=slice(l.output_shape[1]*3/4,l.output_shape[1]),axis=1) l_1q = drop(l_1q, p=0.75) l_1q = nn.layers.GlobalPoolLayer(l_1q, pool_function=T.mean) l_2q = nn.layers.GlobalPoolLayer(l_2q, pool_function=T.max) l_2q = drop(l_2q, p=0.75) l_3q = drop(l_3q, p=0.75) l_3q = nn.layers.GlobalPoolLayer(l_3q, pool_function=T.var) l_4q = nn.layers.FeaturePoolLayer(l_4q, pool_size=64, pool_function=T.max) l_4q = nn.layers.flatten(l_4q) l_4q = drop(l_4q, p=0.75) l_feat = nn.layers.ConcatLayer([l_1q, l_2q, l_3q, l_4q]) l = nn.layers.DenseLayer(l_feat, num_units=p_transform['n_labels'], W=nn.init.Orthogonal(), b=nn.init.Constant(0.5), nonlinearity=nn.nonlinearities.identity) l_weather = nn.layers.SliceLayer(l, indices=slice(0,4), axis=-1) l_weather = nn.layers.NonlinearityLayer(l_weather, nonlinearity=nn.nonlinearities.softmax) l_other = nn_planet.MajorExclusivityLayer(l, idx_major=0) l_other = nn.layers.SliceLayer(l_other, indices=slice(4,None), axis=-1) l_out = nn.layers.ConcatLayer([l_weather, l_other], axis=-1) return namedtuple('Model', ['l_in', 'l_out', 'l_target', 'l_feat'])(l_in, l_out, l_target, l_feat)
def build_model(l_in=None): l_in = nn.layers.InputLayer((None, p_transform['channels'],) + p_transform['patch_size']) if l_in is None else l_in l_target = nn.layers.InputLayer((None,p_transform['n_labels'])) l = conv(l_in, 64) l = inrn_v2_red(l) b1 = inrn_v2(l) l = inrn_v2_red(b1) b2 = inrn_v2(l) l = inrn_v2_red(b2) b3 = inrn_v2(l) l = inrn_v2_red(b3) b4 = inrn_v2(l) l = inrn_v2_red(b4) b5 = inrn_v2(l) l = drop(b5) l = feat_red(l) l = nn.layers.GlobalPoolLayer(l) spp_b1 = nn.layers.FlattenLayer(max_pool(c1(b1,16), pool_size=32)) spp_b2 = nn.layers.FlattenLayer(max_pool(c1(b2,16), pool_size=16)) spp_b3 = nn.layers.FlattenLayer(max_pool(c1(b3,16), pool_size=8)) spp_b4 = nn.layers.FlattenLayer(max_pool(c1(b4,16), pool_size=4)) print 'l', l.output_shape print 'spp_b1', spp_b1.output_shape print 'spp_b2', spp_b2.output_shape print 'spp_b3', spp_b3.output_shape print 'spp_b4', spp_b4.output_shape l_feat = lasagne.layers.ConcatLayer([l, spp_b1, spp_b2, spp_b3, spp_b4]) l = nn.layers.DenseLayer(l_feat, num_units=p_transform['n_labels'], W=nn.init.Orthogonal(), b=nn.init.Constant(0.5), nonlinearity=nn.nonlinearities.identity) l_weather = nn.layers.SliceLayer(l, indices=slice(0,4), axis=-1) l_weather = nn.layers.NonlinearityLayer(l_weather, nonlinearity=nn.nonlinearities.softmax) l_other = nn_planet.MajorExclusivityLayer(l, idx_major=0) l_other = nn.layers.SliceLayer(l_other, indices=slice(4,None), axis=-1) l_out = nn.layers.ConcatLayer([l_weather, l_other], axis=-1) return namedtuple('Model', ['l_in', 'l_out', 'l_target', 'l_feat'])(l_in, l_out, l_target, l_feat)
def build_model(l_in=None): l_in = nn.layers.InputLayer(( None, p_transform['channels'], ) + p_transform['patch_size']) if l_in is None else l_in l_target = nn.layers.InputLayer((None, p_transform['n_labels'])) l = conv(l_in, 64) l = inrn_v2_red(l) l = inrn_v2(l) l = inrn_v2_red(l) l = inrn_v2(l) l = inrn_v2_red(l) l = inrn_v2(l) l = inrn_v2_red(l) l = inrn_v2(l) l = inrn_v2_red(l) l = drop(l, p=0.3) l = inrn_v2(l) l = drop(l, p=0.5) l_feat = nn.layers.GlobalPoolLayer(l) l = nn.layers.DenseLayer(l_feat, num_units=p_transform['n_labels'], W=nn.init.Orthogonal(), b=nn.init.Constant(0.5), nonlinearity=nn.nonlinearities.identity) l_weather = nn.layers.SliceLayer(l, indices=slice(0, 4), axis=-1) l_weather = nn.layers.NonlinearityLayer( l_weather, nonlinearity=nn.nonlinearities.softmax) l_other = nn_planet.MajorExclusivityLayer(l, idx_major=0) l_other = nn.layers.SliceLayer(l_other, indices=slice(4, None), axis=-1) l_out = nn.layers.ConcatLayer([l_weather, l_other], axis=-1) return namedtuple('Model', ['l_in', 'l_out', 'l_target', 'l_feat'])(l_in, l_out, l_target, l_feat)