def __init__(self, n_filter=128, in_channels=128, strides=(1, 1), exp_ratio=6, data_format="channels_first"): super().__init__() self.n_filter = n_filter self.in_channels = in_channels self.strides = strides self.exp_ratio = exp_ratio self.data_format = data_format self.hidden_dim = self.exp_ratio * self.in_channels self.identity = False if (self.strides == (1, 1) and self.in_channels == self.n_filter): self.identity = True if (self.exp_ratio == 1): self.main_block=LayerList([ DepthwiseConv2d(in_channels=self.hidden_dim,filter_size=(3,3),strides=self.strides,\ b_init=None,data_format=self.data_format), BatchNorm2d(num_features=self.hidden_dim,is_train=True,act=tf.nn.relu6,data_format=self.data_format), Conv2d(n_filter=self.n_filter,in_channels=self.hidden_dim,filter_size=(1,1),strides=(1,1),b_init=None,data_format=self.data_format), BatchNorm2d(num_features=self.n_filter,is_train=True,act=None,data_format=self.data_format) ]) else: self.main_block=LayerList([ Conv2d(n_filter=self.hidden_dim,in_channels=self.in_channels,filter_size=(1,1),strides=(1,1),b_init=None,data_format=self.data_format), BatchNorm2d(num_features=self.hidden_dim,is_train=True,act=tf.nn.relu6,data_format=self.data_format), DepthwiseConv2d(in_channels=self.hidden_dim,filter_size=(3,3),strides=self.strides,\ b_init=None,data_format=self.data_format), BatchNorm2d(num_features=self.hidden_dim,is_train=True,act=tf.nn.relu6,data_format=self.data_format), Conv2d(n_filter=self.n_filter,in_channels=self.hidden_dim,filter_size=(1,1),strides=(1,1),b_init=None,data_format=self.data_format) ])
def __init__(self,K_size=18,L_size=17,win=384,hin=384,wout=12,hout=12,wnei=9,hnei=9\ ,lmd_rsp=0.25,lmd_iou=1,lmd_coor=5,lmd_size=5,lmd_limb=0.5,backbone=None,data_format="channels_first"): super().__init__() #construct params self.K = K_size self.L = L_size self.win = win self.hin = hin self.wout = wout self.hout = hout self.hnei = hnei self.wnei = wnei self.n_pos = K_size self.lmd_rsp = lmd_rsp self.lmd_iou = lmd_iou self.lmd_coor = lmd_coor self.lmd_size = lmd_size self.lmd_limb = lmd_limb self.data_format = data_format self.output_dim = 6 * self.K + self.hnei * self.wnei * self.L #construct networks if (backbone == None): self.backbone = self.Resnet_18(n_filter=512, in_channels=3, data_format=data_format) else: self.backbone = backbone(scale_size=32, data_format=self.data_format) self.add_layer_1 = LayerList([ Conv2d(n_filter=512, in_channels=self.backbone.out_channels, filter_size=(3, 3), strides=(1, 1), data_format=self.data_format), BatchNorm2d(decay=0.9, act=lambda x: tl.act.leaky_relu(x, alpha=0.1), is_train=True, num_features=512, data_format=self.data_format) ]) self.add_layer_2 = LayerList([ Conv2d(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1), data_format=self.data_format), BatchNorm2d(decay=0.9, act=lambda x: tl.act.leaky_relu(x, alpha=0.1), is_train=True, num_features=512, data_format=self.data_format) ]) self.add_layer_3 = Conv2d(n_filter=self.output_dim, in_channels=512, filter_size=(1, 1), strides=(1, 1), data_format=self.data_format)
def __init__(self, in_channels=64, n_filter=64, strides=(1, 1), data_format="channels_first"): super().__init__() self.in_channels = in_channels self.n_filter = n_filter self.strides = strides self.data_format = data_format self.downsample = None if (self.strides != (1, 1) or self.in_channels != 4 * self.n_filter): self.downsample=LayerList([ Conv2d(n_filter=4*self.n_filter,in_channels=self.in_channels,filter_size=(1,1),strides=self.strides,b_init=None,\ data_format=self.data_format), BatchNorm2d(is_train=True,num_features=4*self.n_filter,data_format=self.data_format) ]) self.main_block = LayerList([ Conv2d(n_filter=self.n_filter, in_channels=self.in_channels, filter_size=(1, 1), strides=(1, 1), b_init=None, data_format=self.data_format), BatchNorm2d(is_train=True, num_features=self.n_filter, act=tf.nn.relu, data_format=self.data_format), Conv2d(n_filter=self.n_filter, in_channels=self.n_filter, filter_size=(3, 3), strides=self.strides, b_init=None, data_format=self.data_format), BatchNorm2d(is_train=True, num_features=self.n_filter, act=tf.nn.relu, data_format=self.data_format), Conv2d(n_filter=4 * self.n_filter, in_channels=self.n_filter, filter_size=(1, 1), strides=(1, 1), b_init=None, data_format=self.data_format), BatchNorm2d( is_train=True, num_features=4 * self.n_filter, data_format=self.data_format, ) ])
def __init__(self,n_filter,in_channels,strides=(1,1),is_down_sample=False,data_format="channels_first"): super().__init__() self.data_format=data_format self.is_down_sample=is_down_sample self.main_block=LayerList([ Conv2d(n_filter=n_filter,in_channels=in_channels,filter_size=(3,3),strides=strides,b_init=None,data_format=self.data_format), BatchNorm2d(decay=0.9,act=tf.nn.relu,is_train=True,num_features=n_filter,data_format=self.data_format), Conv2d(n_filter=n_filter,in_channels=n_filter,filter_size=(3,3),strides=(1,1),b_init=None,data_format=self.data_format), BatchNorm2d(decay=0.9,is_train=True,num_features=n_filter,data_format=self.data_format), ]) if(self.is_down_sample): self.down_sample=LayerList([ Conv2d(n_filter=n_filter,in_channels=in_channels,filter_size=(3,3),strides=strides,b_init=None,data_format=self.data_format), BatchNorm2d(decay=0.9,is_train=True,num_features=n_filter,data_format=self.data_format) ])
def __init__(self,n_pos=19,n_limbs=19,num_channels=128,hin=368,win=368,hout=46,wout=46,backbone=None,pretrained_backbone=True,data_format="channels_first"): super().__init__() self.num_channels=num_channels self.n_pos=n_pos self.n_limbs=n_limbs self.n_confmaps=n_pos self.n_pafmaps=2*n_limbs self.hin=hin self.win=win self.hout=hout self.wout=wout self.data_format=data_format self.pretrained_backbone=pretrained_backbone self.concat_dim=1 if self.data_format=="channels_first" else -1 #back bone configure if(backbone==None): self.backbone=self.vgg19(in_channels=3,pretrained=self.pretrained_backbone,data_format=self.data_format) else: self.backbone=backbone(scale_size=8,data_format=self.data_format) self.cpm_stage=LayerList([ Conv2d(n_filter=256,in_channels=self.backbone.out_channels,filter_size=(3,3),strides=(1,1),padding="SAME",act=tf.nn.relu,data_format=self.data_format), Conv2d(n_filter=128,in_channels=256,filter_size=(3,3),strides=(1,1),padding="SAME",act=tf.nn.relu,data_format=self.data_format) ]) #init stage self.init_stage=self.Init_stage(n_confmaps=self.n_confmaps, n_pafmaps=self.n_pafmaps,in_channels=128,data_format=self.data_format) #one refinemnet stage self.refinement_stage_1=self.Refinement_stage(n_confmaps=self.n_confmaps, n_pafmaps=self.n_pafmaps, in_channels=self.n_confmaps+self.n_pafmaps+128,data_format=self.data_format) self.refinement_stage_2=self.Refinement_stage(n_confmaps=self.n_confmaps, n_pafmaps=self.n_pafmaps, in_channels=self.n_confmaps+self.n_pafmaps+128,data_format=self.data_format) self.refinement_stage_3=self.Refinement_stage(n_confmaps=self.n_confmaps, n_pafmaps=self.n_pafmaps, in_channels=self.n_confmaps+self.n_pafmaps+128,data_format=self.data_format) self.refinement_stage_4=self.Refinement_stage(n_confmaps=self.n_confmaps, n_pafmaps=self.n_pafmaps, in_channels=self.n_confmaps+self.n_pafmaps+128,data_format=self.data_format) self.refinement_stage_5=self.Refinement_stage(n_confmaps=self.n_confmaps, n_pafmaps=self.n_pafmaps, in_channels=self.n_confmaps+self.n_pafmaps+128,data_format=self.data_format)
def separable_conv_block(self, n_filter=32, in_channels=3, filter_size=(3, 3), strides=(1, 1)): layer_list = [] layer_list.append( DepthwiseConv2d(in_channels=in_channels, filter_size=filter_size, strides=strides, data_format=self.data_format)) layer_list.append( BatchNorm2d(num_features=in_channels, is_train=True, act=tf.nn.relu, data_format=self.data_format)) layer_list.append( Conv2d(n_filter=n_filter, in_channels=in_channels, filter_size=(1, 1), strides=(1, 1), data_format=self.data_format)) layer_list.append( BatchNorm2d(num_features=n_filter, is_train=True, act=tf.nn.relu, data_format=self.data_format)) return LayerList(layer_list)
def make_layers(config, batch_norm=False, end_with='outputs'): layer_list = [] is_end = False for layer_group_idx, layer_group in enumerate(config): if isinstance(layer_group, list): for idx, layer in enumerate(layer_group): layer_name = layer_names[layer_group_idx][idx] n_filter = layer if idx == 0: if layer_group_idx > 0: in_channels = config[layer_group_idx - 2][-1] else: in_channels = 3 else: in_channels = layer layer_list.append( Conv2d(n_filter=n_filter, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=in_channels, name=layer_name)) if batch_norm: layer_list.append(BatchNorm()) if layer_name == end_with: is_end = True break else: layer_name = layer_names[layer_group_idx] if layer_group == 'M': layer_list.append( MaxPool2d(filter_size=(2, 2), strides=(2, 2), padding='SAME', name=layer_name)) elif layer_group == 'O': layer_list.append( Dense(n_units=1000, in_channels=4096, name=layer_name)) elif layer_group == 'F': layer_list.append(Flatten(name='flatten')) elif layer_group == 'fc1': layer_list.append( Dense(n_units=4096, act=tf.nn.relu, in_channels=512 * 7 * 7, name=layer_name)) elif layer_group == 'fc2': layer_list.append( Dense(n_units=4096, act=tf.nn.relu, in_channels=4096, name=layer_name)) if layer_name == end_with: is_end = True if is_end: break return LayerList(layer_list)
def __init__(self): super(CustomModelHidden, self).__init__() self.dropout1 = Dropout(keep=0.8) #(self.innet) self.seq = LayerList([ Dense(n_units=800, act=tf.nn.relu, in_channels=784), Dropout(keep=0.8), Dense(n_units=800, act=tf.nn.relu, in_channels=800), ]) self.dropout3 = Dropout(keep=0.8) #(self.seq)
def __init__(self,n_confmaps=19,n_pafmaps=38,in_channels=19+38+704,data_format="channels_first"): self.n_confmaps=n_confmaps self.n_pafmaps=n_pafmaps self.in_channels=in_channels self.data_format=data_format #conf_block self.conf_block=LayerList([ separable_block(n_filter=128,in_channels=self.in_channels,filter_size=(7,7),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=128,in_channels=128,filter_size=(7,7),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=128,in_channels=128,filter_size=(7,7),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=128,in_channels=128,filter_size=(1,1),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=self.n_confmaps,in_channels=128,filter_size=(1,1),strides=(1,1),act=None,data_format=self.data_format), ]) #paf_block self.conf_block=LayerList([ separable_block(n_filter=128,in_channels=self.in_channels,filter_size=(7,7),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=128,in_channels=128,filter_size=(7,7),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=128,in_channels=128,filter_size=(7,7),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=128,in_channels=128,filter_size=(1,1),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=self.n_pafmaps,in_channels=128,filter_size=(1,1),strides=(1,1),act=None,data_format=self.data_format), ])
def __init__(self,n_confmaps=19,n_pafmaps=38,in_channels=1152,data_format="channels_first"): super().__init__() self.n_confmaps=n_confmaps self.n_pafmaps=n_pafmaps self.in_channels=in_channels self.data_format=data_format #conf block self.conf_block=LayerList([ separable_block(n_filter=128,in_channels=self.in_channels,filter_size=(3,3),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=128,in_channels=128,filter_size=(3,3),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=128,in_channels=128,filter_size=(3,3),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=512,in_channels=128,filter_size=(1,1),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=self.n_confmaps,in_channels=512,filter_size=(1,1),strides=(1,1),act=None,data_format=self.data_format) ]) #paf block self.paf_block=LayerList([ separable_block(n_filter=128,in_channels=self.in_channels,filter_size=(3,3),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=128,in_channels=128,filter_size=(3,3),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=128,in_channels=128,filter_size=(3,3),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=512,in_channels=128,filter_size=(1,1),strides=(1,1),act=tf.nn.relu,data_format=self.data_format), separable_block(n_filter=self.n_pafmaps,in_channels=512,filter_size=(1,1),strides=(1,1),act=None,data_format=self.data_format) ])
def conv_block(self, n_filter=32, in_channels=3, filter_size=(3, 3), strides=(1, 1), padding="SAME"): layer_list = [] layer_list.append(Conv2d(n_filter=n_filter,in_channels=in_channels,filter_size=filter_size,strides=strides,\ data_format=self.data_format,padding=padding)) layer_list.append( BatchNorm2d(num_features=n_filter, is_train=True, act=tf.nn.relu, data_format=self.data_format)) return LayerList(layer_list)
def separable_block(n_filter=32, in_channels=3, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding="SAME", data_format="channels_first"): layer_list = [] layer_list.append(SeparableConv2d(n_filter=n_filter,in_channels=in_channels,filter_size=filter_size,strides=strides,act=act,\ data_format=data_format,padding=padding)) layer_list.append( BatchNorm2d(num_features=n_filter, decay=0.999, is_train=True, act=act, data_format=data_format)) return LayerList(layer_list)
def __init__(self, end_with='outputs', name=None): super(VGG19, self).__init__() self.end_with = end_with self.layer_names = ['conv1_1', 'conv1_2', 'pool1', 'conv2_1', 'conv2_2', 'pool2', 'conv3_1', 'conv3_2', 'conv3_3', 'conv3_4', 'pool3', 'conv4_1', 'conv4_2', 'conv4_3', 'conv4_4', 'pool4', 'conv5_1', 'conv5_2', 'conv5_3', 'conv5_4', 'pool5', 'flatten', 'fc1_relu', 'fc2_relu', 'outputs'] self.innet = Input([None, 224, 224, 3]) self.layers = LayerList([ # conv1 Conv2d(n_filter=64, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=3, name='conv1_1'), Conv2d(n_filter=64, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=64, name='conv1_2'), MaxPool2d(filter_size=(2, 2), strides=(2, 2), padding='SAME', name='pool1'), # conv2 Conv2d(n_filter=128, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=64, name='conv2_1'), Conv2d(n_filter=128, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=128, name='conv2_2'), MaxPool2d(filter_size=(2, 2), strides=(2, 2), padding='SAME', name='pool2'), # conv3 Conv2d(n_filter=256, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=128, name='conv3_1'), Conv2d(n_filter=256, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=256, name='conv3_2'), Conv2d(n_filter=256, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=256, name='conv3_3'), Conv2d(n_filter=256, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=256, name='conv3_4'), MaxPool2d(filter_size=(2, 2), strides=(2, 2), padding='SAME', name='pool3'), # conv4 Conv2d(n_filter=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=256, name='conv4_1'), Conv2d(n_filter=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=512, name='conv4_2'), Conv2d(n_filter=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=512, name='conv4_3'), Conv2d(n_filter=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=512, name='conv4_4'), MaxPool2d(filter_size=(2, 2), strides=(2, 2), padding='SAME', name='pool4'), # conv5 Conv2d(n_filter=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=512, name='conv5_1'), Conv2d(n_filter=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=512, name='conv5_2'), Conv2d(n_filter=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=512, name='conv5_3'), Conv2d(n_filter=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu, padding='SAME', in_channels=512, name='conv5_4'), MaxPool2d(filter_size=(2, 2), strides=(2, 2), padding='SAME', name='pool5'), Flatten(name='flatten'), Dense(n_units=4096, act=tf.nn.relu, in_channels=512*7*7, name='fc1_relu'), Dense(n_units=4096, act=tf.nn.relu, in_channels=4096, name='fc2_relu'), Dense(n_units=1000, in_channels=4096, name='outputs'), ][:self.layer_names.index(self.end_with) + 1])
def __init__(self, feature_hin, feature_win, in_channels, data_format="channels_first"): super().__init__() self.data_format = data_format self.feature_hin = feature_hin self.feature_win = feature_win self.in_channels = in_channels self.layer_num = 5 self.n_filter = 256 # construct Model layer_list = [] last_channels = self.in_channels dis_hin, dis_win = self.feature_hin, self.feature_win for layer_idx in range(0, self.layer_num): strides = (1, 1) if (dis_hin >= 4 or dis_win >= 4): strides = (2, 2) dis_hin, dis_win = (dis_hin + 1) // 2, (dis_win + 1) // 2 layer_list+=[ Conv2d(n_filter=self.n_filter,in_channels=last_channels,strides=strides,act=tf.nn.relu,\ data_format=data_format,name=f"dis_conv_{layer_idx}") ] last_channels = self.n_filter layer_list.append(Flatten(name="Flatten")) layer_list.append( Dense(n_units=4096, in_channels=dis_hin * dis_win * self.n_filter, act=tf.nn.relu, name="fc1")) layer_list.append( Dense(n_units=1000, in_channels=4096, act=tf.nn.relu, name="fc2")) layer_list.append( Dense(n_units=1, in_channels=1000, act=None, name="fc3")) self.main_block = LayerList(layer_list)
def __init__(self, layer_list, data_format="channels_first"): self.data_format = data_format self.main_block = LayerList(layer_list)
def make_layers(config, batch_norm=False, end_with='outputs', is_reversed=False, input_depth=3): layer_list = [] is_end = False for layer_group_idx, layer_group in enumerate(config): is_last_group = (layer_group_idx == len(config) - 1) if isinstance(layer_group, list): for idx, layer in enumerate( layer_group ): # NOTE: here 'layer' means n_filter of the Conv2d layer is_last_layer = is_last_group and (idx == len(layer_group) - 1) layer_name = layer_names[layer_group_idx][ idx] if not is_reversed else layer_names_rev[ layer_group_idx][idx] n_filter = layer if idx == 0: if layer_group_idx > 0: in_channels = config[layer_group_idx - 2][-1] else: # TL1to2: possibly be 1, or other depth value of input (e.g. features) in_channels = input_depth else: # TL1to2: should trace the previous n_filter # in_channels = layer in_channels = layer_group[idx - 1] if not (is_reversed and _use_DeConv2d): # NOTE: customized padding to avoid border artifacts if _use_PadLayer_Reflect: layer_list.append( PadLayer([[0, 0], [1, 1], [1, 1], [0, 0]], mode="REFLECT")) layer_list.append( Conv2d(n_filter=n_filter, filter_size=(3, 3), strides=(1, 1), padding='VALID' if _use_PadLayer_Reflect else 'SAME', act=_relu_class if not batch_norm and not is_last_layer else None, in_channels=in_channels, name=layer_name)) else: # NOTE: DeConv2d is 1-N reverse mapping, cannot use Padding before calling DeConv2d layer_list.append( DeConv2d_before_merge(n_filter=n_filter, filter_size=(3, 3), strides=(1, 1), padding='SAME', act=_relu_class if not batch_norm and not is_last_layer else None, in_channels=in_channels, name=layer_name)) if batch_norm and not is_last_layer: # layer_list.append(BatchNorm()) layer_list.append( BatchNorm2d_before_merged(num_features=n_filter, act=_relu_class)) if layer_name == end_with: is_end = True break else: layer_name = layer_names[ layer_group_idx] if not is_reversed else layer_names_rev[ layer_group_idx] if layer_group == 'M': layer_list.append( MaxPool2d(filter_size=(2, 2), strides=(2, 2), padding='SAME', name=layer_name)) elif layer_group == 'U': layer_list.append( UpSampling2d(scale=(2, 2), method='nearest', name=layer_name)) elif layer_group == 'O': layer_list.append( Dense(n_units=1000, in_channels=4096, name=layer_name)) elif layer_group == 'F': layer_list.append(Flatten(name='flatten')) elif layer_group == 'fc1': layer_list.append( Dense(n_units=4096, act=_relu_class, in_channels=512 * 7 * 7, name=layer_name)) elif layer_group == 'fc2': layer_list.append( Dense(n_units=4096, act=_relu_class, in_channels=4096, name=layer_name)) if layer_name == end_with: is_end = True if is_end: break # TL1to2: may use LayerList_before_merge, which overrode forward() to observe intermediate outputs if _use_LayerList_before_merge: tl.logging.warning( 'Using LayerList_before_merge... consider merging to master branch.' ) return LayerList_before_merge(layer_list) else: return LayerList(layer_list)
def __init__(self,parts=CocoPart,limbs=CocoLimb,colors=None,K_size=18,L_size=17,win=384,hin=384,wout=12,hout=12,wnei=9,hnei=9\ ,lmd_rsp=0.25,lmd_iou=1,lmd_coor=5,lmd_size=5,lmd_limb=0.5,backbone=None,pretraining=False,data_format="channels_first"): super().__init__() #construct params self.parts = parts self.limbs = limbs self.colors = colors self.K = K_size self.L = L_size self.win = win self.hin = hin self.wout = wout self.hout = hout self.hnei = hnei self.wnei = wnei self.n_pos = K_size self.lmd_rsp = lmd_rsp self.lmd_iou = lmd_iou self.lmd_coor = lmd_coor self.lmd_size = lmd_size self.lmd_limb = lmd_limb self.data_format = data_format self.output_dim = 6 * self.K + self.hnei * self.wnei * self.L #construct networks if (backbone == None): self.backbone = Resnet18_backbone(scale_size=32, pretraining=pretraining, data_format=data_format) else: self.backbone = backbone(scale_size=32, pretraining=pretraining, data_format=self.data_format) self.add_layer_1 = LayerList([ Conv2d(n_filter=512, in_channels=self.backbone.out_channels, filter_size=(3, 3), strides=(1, 1), data_format=self.data_format, name="add_block_1_conv_1"), BatchNorm2d(decay=0.9, act=lambda x: tl.act.leaky_relu(x, alpha=0.1), is_train=True, num_features=512, data_format=self.data_format, name="add_block_1_bn_1"), ], name="add_block_1") self.add_layer_2 = LayerList([ Conv2d(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1), data_format=self.data_format, name="add_block_2_conv_1"), BatchNorm2d(decay=0.9, act=lambda x: tl.act.leaky_relu(x, alpha=0.1), is_train=True, num_features=512, data_format=self.data_format, name="add_block_2_bn_1") ], name="add_block_2") self.add_layer_3 = Conv2d(n_filter=self.output_dim, in_channels=512, filter_size=(1, 1), strides=(1, 1), data_format=self.data_format, name="add_block_3_conv_1")
def __init__(self, scale_size=8, data_format="channel_last"): super().__init__() self.data_format = data_format self.scale_size = scale_size if (self.scale_size == 8): strides = (1, 1) else: strides = (2, 2) self.out_channels = 1024 self.layer_list = [] self.layer_list += self.conv_block(n_filter=32, in_channels=3, filter_size=(3, 3), strides=(2, 2)) self.layer_list += self.separable_conv_block(n_filter=64, in_channels=32, filter_size=(3, 3), strides=(1, 1)) self.layer_list += self.separable_conv_block(n_filter=128, in_channels=64, filter_size=(3, 3), strides=(2, 2)) self.layer_list += self.separable_conv_block(n_filter=128, in_channels=128, filter_size=(3, 3), strides=(1, 1)) self.layer_list += self.separable_conv_block(n_filter=256, in_channels=128, filter_size=(3, 3), strides=(2, 2)) self.layer_list += self.separable_conv_block(n_filter=256, in_channels=256, filter_size=(3, 3), strides=(1, 1)) self.layer_list += self.separable_conv_block(n_filter=512, in_channels=256, filter_size=(3, 3), strides=strides) self.layer_list += self.separable_conv_block(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1)) self.layer_list += self.separable_conv_block(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1)) self.layer_list += self.separable_conv_block(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1)) self.layer_list += self.separable_conv_block(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1)) self.layer_list += self.separable_conv_block(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1)) self.layer_list += self.separable_conv_block(n_filter=1024, in_channels=512, filter_size=(3, 3), strides=strides) self.layer_list += self.separable_conv_block(n_filter=1024, in_channels=1024, filter_size=(3, 3), strides=(1, 1)) self.main_block = LayerList(self.layer_list)
def __init__(self, in_channels=3, scale_size=8, data_format="channels_first"): super().__init__() self.in_channels = in_channels self.data_format = data_format self.scale_size = scale_size if (self.scale_size == 8): strides = (1, 1) else: strides = (2, 2) self.out_channels = 512 self.layer_list = [ self.conv_block(n_filter=64, in_channels=self.in_channels, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), self.conv_block(n_filter=64, in_channels=64, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), MaxPool2d(filter_size=(2, 2), strides=(2, 2), data_format=self.data_format), self.conv_block(n_filter=128, in_channels=64, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), self.conv_block(n_filter=128, in_channels=128, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), MaxPool2d(filter_size=(2, 2), strides=(2, 2), data_format=self.data_format), self.conv_block(n_filter=256, in_channels=128, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), self.conv_block(n_filter=256, in_channels=256, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), self.conv_block(n_filter=256, in_channels=256, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), self.conv_block(n_filter=256, in_channels=256, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), MaxPool2d(filter_size=(2, 2), strides=(2, 2), data_format=self.data_format), self.conv_block(n_filter=512, in_channels=256, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), self.conv_block(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), self.conv_block(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), self.conv_block(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu) ] if (self.scale_size == 32): self.layer_list += [ MaxPool2d(filter_size=(2, 2), strides=(2, 2), data_format=self.data_format) ] self.layer_list += [ self.conv_block(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), self.conv_block(n_filter=512, in_channels=512, filter_size=(3, 3), strides=strides, act=tf.nn.relu), self.conv_block(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu), self.conv_block(n_filter=512, in_channels=512, filter_size=(3, 3), strides=(1, 1), act=tf.nn.relu) ] self.main_block = LayerList(self.layer_list)