def multibox_head(source_layers, num_priors, normalizations=None, softmax=True): num_classes = 2 class_activation = 'softmax' if softmax else 'sigmoid' mbox_conf = [] mbox_loc = [] mbox_quad = [] mbox_rbox = [] for i in range(len(source_layers)): x = source_layers[i] name = x.name.split('/')[0] # normalize if normalizations is not None and normalizations[i] > 0: name = name + '_norm' x = Normalize(normalizations[i], name=name)(x) # confidence name1 = name + '_mbox_conf' x1 = Conv2D(num_priors[i] * num_classes, (3, 5), padding='same', name=name1)(x) x1 = Flatten(name=name1+'_flat')(x1) mbox_conf.append(x1) # location, Delta(x,y,w,h) name2 = name + '_mbox_loc' x2 = Conv2D(num_priors[i] * 4, (3, 5), padding='same', name=name2)(x) x2 = Flatten(name=name2+'_flat')(x2) mbox_loc.append(x2) # quadrilateral, Delta(x1,y1,x2,y2,x3,y3,x4,y4) name3 = name + '_mbox_quad' x3 = Conv2D(num_priors[i] * 8, (3, 5), padding='same', name=name3)(x) x3 = Flatten(name=name3+'_flat')(x3) mbox_quad.append(x3) # rotated rectangle, Delta(x1,y1,x2,y2,h) name4 = name + '_mbox_rbox' x4 = Conv2D(num_priors[i] * 5, (3, 5), padding='same', name=name4)(x) x4 = Flatten(name=name4+'_flat')(x4) mbox_rbox.append(x4) mbox_conf = concatenate(mbox_conf, axis=1, name='mbox_conf') mbox_conf = Reshape((-1, num_classes), name='mbox_conf_logits')(mbox_conf) mbox_conf = Activation(class_activation, name='mbox_conf_final')(mbox_conf) mbox_loc = concatenate(mbox_loc, axis=1, name='mbox_loc') mbox_loc = Reshape((-1, 4), name='mbox_loc_final')(mbox_loc) mbox_quad = concatenate(mbox_quad, axis=1, name='mbox_quad') mbox_quad = Reshape((-1, 8), name='mbox_quad_final')(mbox_quad) mbox_rbox = concatenate(mbox_rbox, axis=1, name='mbox_rbox') mbox_rbox = Reshape((-1, 5), name='mbox_rbox_final')(mbox_rbox) predictions = concatenate([mbox_loc, mbox_quad, mbox_rbox, mbox_conf], axis=2, name='predictions') return predictions
def multibox_head(source_layers, num_priors, num_classes, normalizations=None, softmax=True): mbox_conf = [] mbox_loc = [] for i in range(len(source_layers)): x = source_layers[i] name = x.name.split('/')[0] # normalize if normalizations is not None and normalizations[i] > 0: name = name + '_norm' x = Normalize(normalizations[i], name=name)(x) # confidence name1 = name + '_mbox_conf' x1 = Conv2D(num_priors[i] * num_classes, (1, 5), padding='same', name=name1)(x) x1 = Flatten(name=name1 + '_flat')(x1) mbox_conf.append(x1) # location name2 = name + '_mbox_loc' x2 = Conv2D(num_priors[i] * 4, (1, 5), padding='same', name=name2)(x) x2 = Flatten(name=name2 + '_flat')(x2) mbox_loc.append(x2) mbox_loc = concatenate(mbox_loc, axis=1, name='mbox_loc') mbox_loc = Reshape((-1, 4), name='mbox_loc_final')(mbox_loc) mbox_conf = concatenate(mbox_conf, axis=1, name='mbox_conf') mbox_conf = Reshape((-1, num_classes), name='mbox_conf_logits')(mbox_conf) if softmax: mbox_conf = Activation('softmax', name='mbox_conf_final')(mbox_conf) else: mbox_conf = Activation('sigmoid', name='mbox_conf_final')(mbox_conf) predictions = concatenate([mbox_loc, mbox_conf], axis=2, name='predictions') return predictions
def multibox_head(source_layers, num_priors, normalizations=None, softmax=True): num_classes = 2 class_activation = 'softmax' if softmax else 'sigmoid' mbox_conf = [] mbox_loc = [] link_interlayer_conf = [] link_crosslayer_conf = [] for i in range(len(source_layers)): x = source_layers[i] name = x.name.split('/')[0] # normalize if normalizations is not None and normalizations[i] > 0: name = name + '_norm' x = Normalize(normalizations[i], name=name)(x) # confidence name1 = name + '_mbox_conf' x1 = Conv2D(num_priors[i] * num_classes, 3, padding='same', name=name1)(x) x1 = Flatten(name=name1+'_flat')(x1) mbox_conf.append(x1) # location name2 = name + '_mbox_loc' x2 = Conv2D(num_priors[i] * 5, 3, padding='same', name=name2)(x) x2 = Flatten(name=name2+'_flat')(x2) mbox_loc.append(x2) # link interlayer confidenc name3 = name + '_link_interlayer_conf' x3 = Conv2D(num_priors[i] * num_classes * 8, 3, padding='same', name=name3)(x) x3 = Flatten(name=name3+'_flat')(x3) link_interlayer_conf.append(x3) # link crosslayer confidenc name4 = name + '_link_crosslayer_conf' x4 = Conv2D(num_priors[i] * num_classes * 4, 3, padding='same', name=name4)(x) x4 = Flatten(name=name4+'_flat')(x4) link_crosslayer_conf.append(x4) mbox_conf = concatenate(mbox_conf, axis=1, name='mbox_conf') mbox_conf = Reshape((-1, num_classes), name='mbox_conf_logits')(mbox_conf) mbox_conf = Activation(class_activation, name='mbox_conf_final')(mbox_conf) mbox_loc = concatenate(mbox_loc, axis=1, name='mbox_loc') mbox_loc = Reshape((-1, 5), name='mbox_loc_final')(mbox_loc) #link_interlayer_conf = concatenate(link_interlayer_conf, axis=1, name='link_interlayer_conf') #link_interlayer_conf = Reshape((-1, num_classes * 8), name='link_interlayer_conf_logits')(link_interlayer_conf) #link_interlayer_conf = Activation(class_activation, name='link_interlayer_conf_final')(link_interlayer_conf) #link_crosslayer_conf = concatenate(link_crosslayer_conf, axis=1, name='link_crosslayer_conf') #link_crosslayer_conf = Reshape((-1, num_classes * 4), name='link_crosslayer_conf_logits')(link_crosslayer_conf) #link_crosslayer_conf = Activation(class_activation, name='link_crosslayer_conf_final')(link_crosslayer_conf) link_interlayer_conf = concatenate(link_interlayer_conf, axis=1, name='link_interlayer_conf') link_interlayer_conf = Reshape((-1, num_classes), name='link_interlayer_conf_logits')(link_interlayer_conf) link_interlayer_conf = Activation(class_activation, name='link_interlayer_conf_softmax')(link_interlayer_conf) link_interlayer_conf = Reshape((-1, num_classes * 8), name='link_interlayer_conf_final')(link_interlayer_conf) link_crosslayer_conf = concatenate(link_crosslayer_conf, axis=1, name='link_crosslayer_conf') link_crosslayer_conf = Reshape((-1, num_classes), name='link_crosslayer_conf_logits')(link_crosslayer_conf) link_crosslayer_conf = Activation(class_activation, name='link_crosslayer_conf_softmax')(link_crosslayer_conf) link_crosslayer_conf = Reshape((-1, num_classes * 4), name='link_crosslayer_conf_final')(link_crosslayer_conf) predictions = concatenate([ mbox_conf, mbox_loc, link_interlayer_conf, link_crosslayer_conf ], axis=2, name='predictions') return predictions
def multibox_head(source_layers, num_priors, normalizations=None, softmax=True): num_classes = 6 class_activation = 'softmax' if softmax else 'sigmoid' mbox_conf = [] mbox_loc = [] mbox_quad = [] mbox_rbox = [] for i in range(len(source_layers)): x = source_layers[ i] #i=0 => image size of x : (64,64), shape of x : [None, 64, 64, 512] name = x.name.split('/')[0] # normalize if normalizations is not None and normalizations[i] > 0: name = name + '_norm' x = Normalize(normalizations[i], name=name)(x) # confidence name1 = name + '_mbox_conf' x1 = Conv2D( num_priors[i] * num_classes, (3, 5), padding='same', name=name1 )( x ) #num_priors[i]=14, num_classes = 6 => x1 shape : [None, 64, 64, 14*6] x1 = Flatten(name=name1 + '_flat')( x1) # shape of x1: [batch_size, 64*64*14*6], per class : 64*64*14 mbox_conf.append(x1) # location, Delta(x,y,w,h) name2 = name + '_mbox_loc' x2 = Conv2D(num_priors[i] * 4, (3, 5), padding='same', name=name2)(x) x2 = Flatten(name=name2 + '_flat')(x2) mbox_loc.append(x2) # shape of x2: [batch_size, 64*64*14*4] # quadrilateral, Delta(x1,y1,x2,y2,x3,y3,x4,y4) name3 = name + '_mbox_quad' x3 = Conv2D(num_priors[i] * 8, (3, 5), padding='same', name=name3)(x) x3 = Flatten(name=name3 + '_flat')(x3) mbox_quad.append(x3) # shape of x3: [batch_size, 64*64*14*8] # rotated rectangle, Delta(x1,y1,x2,y2,h) name4 = name + '_mbox_rbox' x4 = Conv2D(num_priors[i] * 5, (3, 5), padding='same', name=name4)(x) x4 = Flatten(name=name4 + '_flat')(x4) mbox_rbox.append(x4) # shape of x4: [batch_size, 64*64*14*5] mbox_conf = concatenate(mbox_conf, axis=1, name='mbox_conf') mbox_conf = Reshape( (-1, num_classes), name='mbox_conf_logits')(mbox_conf) #shape : [batch_size, 64*64*14, 6] mbox_conf = Activation(class_activation, name='mbox_conf_final')(mbox_conf) mbox_loc = concatenate(mbox_loc, axis=1, name='mbox_loc') mbox_loc = Reshape( (-1, 4), name='mbox_loc_final')(mbox_loc) #shape : [batch_size, 64*64*14, 4] mbox_quad = concatenate(mbox_quad, axis=1, name='mbox_quad') mbox_quad = Reshape( (-1, 8), name='mbox_quad_final')(mbox_quad) #shape : [batch_size, 64*64*14, 8] mbox_rbox = concatenate(mbox_rbox, axis=1, name='mbox_rbox') mbox_rbox = Reshape( (-1, 5), name='mbox_rbox_final')(mbox_rbox) #shape : [batch_size, 64*64*14, 5] predictions = concatenate([mbox_loc, mbox_quad, mbox_rbox, mbox_conf], axis=2, name='predictions') return predictions # shape : (batch_size,Nums_priors,4+8+5+6) = (batch_size, 76454, 23)