def forward(self, x): c1 = self.block1(x) t = rm.max_pool2d(c1, filter=2, stride=2) c2 = self.block2(t) t = rm.max_pool2d(c2, filter=2, stride=2) c3 = self.block3(t) t = rm.max_pool2d(c3, filter=2, stride=2) c4 = self.block4(t) t = rm.max_pool2d(c4, filter=2, stride=2) c5 = self.block5(t) t = rm.max_pool2d(c5, filter=2, stride=2) t = self.center(t) t = rm.concat([t, c5]) t = self.decoder_block5(t) t = rm.concat([t, c4]) t = self.decoder_block4(t) t = rm.concat([t, c3]) t = self.decoder_block3(t) t = rm.concat([t, c2]) t = self.decoder_block2(t) t = rm.concat([t, c1]) t = self.decoder_block1(t) t = self.final(t) return t
def forward(self, x): """Performs forward propagation. This function can be called using ``__call__`` method. See following example of method usage. Args: x (ndarray, Node): Input image as an tensor. Returns: (Node): Returns raw output of yolo v1. You can reform it to bounding box form using the method ``get_bbox``. Example: >>> import numpy as np >>> from renom_img.api.detection.yolo_v2 import Yolov2 >>> >>> x = np.random.rand(1, 3, 224, 224) >>> class_map = ["dog", "cat"] >>> model = Yolov2(class_map) >>> y = model.forward(x) # Forward propagation. >>> y = model(x) # Same as above result. >>> >>> bbox = model.get_bbox(y) # The output can be reformed using get_bbox method. """ assert len(self.class_map) > 0, \ "Class map is empty. Please set the attribute class_map when instantiate model class. " +\ "Or, please load already trained model using the method 'load()'." assert self.num_anchor > 0, \ "Anchor list is empty. Please calculate anchor list using create_anchor function, before instantiate model class. " +\ "Or, please load already trained model using the method 'load()'." self._freezed_network.set_auto_update(self.train_whole_network) self._freezed_network.set_models(inference=( not self.train_whole_network or getattr(self, 'inference', False))) h, f = self._freezed_network(x) f = self._conv21(f) h = self._conv1(h) h = self._conv2(rm.concat(h, rm.concat([f[:, :, i::2, j::2] for i in range(2) for j in range(2)]))) out = self._last(h) # Create yolo format. N, C, H, W = h.shape reshaped = out.reshape(N, self.num_anchor, -1, W * H) conf = rm.sigmoid(reshaped[:, :, 0:1]).transpose(0, 2, 1, 3) px = rm.sigmoid(reshaped[:, :, 1:2]).transpose(0, 2, 1, 3) py = rm.sigmoid(reshaped[:, :, 2:3]).transpose(0, 2, 1, 3) pw = rm.exp(reshaped[:, :, 3:4]).transpose(0, 2, 1, 3) ph = rm.exp(reshaped[:, :, 4:5]).transpose(0, 2, 1, 3) cl = rm.softmax(reshaped[:, :, 5:].transpose(0, 2, 1, 3)) return rm.concat(conf, px, py, pw, ph, cl).transpose(0, 2, 1, 3).reshape(N, -1, H, W)
def forward(self, x): h = self.pool1(rm.leaky_relu(self.bn1(self.conv1(x)), slope=0.1)) h = self.pool2(rm.leaky_relu(self.bn2(self.conv2(h)), slope=0.1)) h = rm.leaky_relu(self.bn3(self.conv3(h)), slope=0.1) h = rm.leaky_relu(self.bn4(self.conv4(h)), slope=0.1) h = self.pool3(rm.leaky_relu(self.bn5(self.conv5(h)), slope=0.1)) h = rm.leaky_relu(self.bn6(self.conv6(h)), slope=0.1) h = rm.leaky_relu(self.bn7(self.conv7(h)), slope=0.1) h = self.pool4(rm.leaky_relu(self.bn8(self.conv8(h)), slope=0.1)) h = rm.leaky_relu(self.bn9(self.conv9(h)), slope=0.1) h = rm.leaky_relu(self.bn10(self.conv10(h)), slope=0.1) h = rm.leaky_relu(self.bn11(self.conv11(h)), slope=0.1) h = rm.leaky_relu(self.bn12(self.conv12(h)), slope=0.1) h = rm.leaky_relu(self.bn13(self.conv13(h)), slope=0.1) high_resolution_feature = reorg(h) # 高解像度特徴量をreorgでサイズ落として保存しておく h = self.pool5(h) h = rm.leaky_relu(self.bn14(self.conv14(h)), slope=0.1) h = rm.leaky_relu(self.bn15(self.conv15(h)), slope=0.1) h = rm.leaky_relu(self.bn16(self.conv16(h)), slope=0.1) h = rm.leaky_relu(self.bn17(self.conv17(h)), slope=0.1) h = rm.leaky_relu(self.bn18(self.conv18(h)), slope=0.1) ##### detection layer h = rm.leaky_relu(self.bn19(self.conv19(h)), slope=0.1) h = rm.leaky_relu(self.bn20(self.conv20(h)), slope=0.1) h = rm.concat(high_resolution_feature, h) h = rm.leaky_relu(self.bn21(self.conv21(h)), slope=0.1) h = self.conv22(h) return h
def forward(self, x): hidden = self.input(x) #print(hidden.shape) hidden = rm.max_pool2d(hidden, stride=1, padding=1) #print(hidden.shape) layers = self.hidden._layers for i in range(self.blocks): offset = i * (self.depth * 2 + 1) for j in range(self.depth): sub = rm.relu(layers[offset + 2 * j](hidden)) #print('{}.{} b {}'.format(i,j,sub.shape)) sub = layers[offset + 2 * j + 1](sub) #print('{}.{} + {}'.format(i,j,sub.shape)) if self.dropout: sub = rm.dropout(sub) hidden = rm.concat(hidden, sub) #print('{}.{} = {}'.format(i,j,hidden.shape)) offset = (i + 1) * (self.depth * 2 + 1) - 1 hidden = layers[offset](hidden) #print('{}.{} - {}'.format(i,j,hidden.shape)) hidden = rm.average_pool2d(hidden, stride=2, padding=1) #print('{}.{} > {}'.format(i,j,hidden.shape)) x = rm.flatten(hidden) layers = self.fcnn._layers for i in range(len(layers[:-2])): x = rm.relu(layers[i](x)) #print(x.shape) if self.dropout: x = rm.dropout(x, dropout_ratio=0.5) z_mean = layers[-2](x) z_log_var = layers[-1](x) return z_mean, z_log_var
def forward(self, x): t1 = rm.relu(self.batch_norm1_reduced(self.conv1_reduced(x))) t1 = rm.relu(self.batch_norm1_1(self.conv1_1(t1))) t1 = rm.relu(self.batch_norm1_2(self.conv1_2(t1))) t2 = rm.relu(self.batch_norm2(self.conv2(x))) t3 = rm.max_pool2d(x, filter=3, stride=2) return rm.concat([t1, t2, t3])
def test_concat(node, x, use_gpu): node = Variable(node) set_cuda_active(use_gpu) assert np.allclose(rm.concat(node, x), np.concatenate((node, x), 1)) def func(node, x): return sum(rm.concat(node, x)) compare(func, node, node, x)
def forward(self, x): t1 = rm.relu(self.conv1(x)) t2 = rm.relu(self.conv2_reduced(x)) t2 = rm.relu(self.conv2(t2)) t3 = rm.relu(self.conv3_reduced(x)) t3 = rm.relu(self.conv3(t3)) t4 = rm.max_pool2d(x, filter=3, stride=1, padding=1) t4 = rm.relu(self.conv4(t4)) return rm.concat([t1, t2, t3, t4])
def forward(self, x): t1 = rm.relu(self.batch_norm1(self.conv1(x))) t2 = rm.relu(self.batch_norm2_reduced(self.conv2_reduced(x))) t2_1 = rm.relu(self.batch_norm2_1(self.conv2_1(t2))) t2_2 = rm.relu(self.batch_norm2_2(self.conv2_2(t2))) t2 = rm.concat([t2_1, t2_2]) t3 = rm.relu(self.batch_norm3_reduced(self.conv3_reduced(x))) t3 = rm.relu(self.batch_norm3_1(self.conv3_1(t3))) t3_1 = rm.relu(self.batch_norm3_2(self.conv3_2(t3))) t3_2 = rm.relu(self.batch_norm3_3(self.conv3_3(t3))) t3 = rm.concat([t3_1, t3_2]) t4 = rm.max_pool2d(x, filter=3, stride=1, padding=1) t4 = rm.relu(self.batch_norm4(self.conv4(t4))) return rm.concat([ t1, t2, t3, t4 ])
def forward(self, x): hidden = self.batch(x) hidden = rm.tanh(hidden) hidden = self.conv(hidden) if self.dropout: hidden = rm.dropout(hidden) hidden = rm.concat(x, hidden) if self.depth != 1: return self.under_model(hidden) #print(hidden.shape) return self.output(hidden)
def forward(self, x): t = rm.relu(self.batch_norm1(self.conv1(x))) t = rm.relu(self.batch_norm2(self.conv2(t))) t = rm.relu(self.batch_norm3(self.conv3(t))) t1 = rm.max_pool2d(t, filter=3, stride=2) t2 = rm.relu(self.batch_norm4(self.conv4(t))) t = rm.concat([t1, t2]) t1 = rm.relu(self.batch_norm5_1_1(self.conv5_1_1(t))) t1 = rm.relu(self.batch_norm5_1_2(self.conv5_1_2(t1))) t2 = rm.relu(self.batch_norm5_2_1(self.conv5_2_1(t))) t2 = rm.relu(self.batch_norm5_2_2(self.conv5_2_2(t2))) t2 = rm.relu(self.batch_norm5_2_3(self.conv5_2_3(t2))) t2 = rm.relu(self.batch_norm5_2_4(self.conv5_2_4(t2))) t = rm.concat([t1, t2]) t1 = rm.relu(self.batch_norm6(self.conv6(t))) t2 = rm.max_pool2d(t, filter=3, stride=2) return rm.concat([t1, t2])
def _incorp_label(self, x, y, eps=1e-3): nb = len(x) def comp_fm(_dir, dp, idx_f, idx_m): def func(_dir, x): return -rm.sum(rm.log( x+eps if _dir=='pos' else 1-x+eps)) _f = func(_dir, dp[idx_f])/len(idx_f) if len(idx_f) else 0 _m = func(_dir, dp[idx_m])/len(idx_m) if len(idx_m) else 0 return self.fm_rate*_f + _m # generating pz & check positive judge full = int(nb*self.full_rate) perm = random.permutation(nb) pz_label = np.zeros((nb, self.label_dim+1)) pz_f_idx, pz_m_idx = perm[full:], perm[:full] self.types[pz_f_idx] = self.label_dim pz_label[np.arange(nb), self.types] = 1 self.pz = rm.concat(self.pz, pz_label) self.Dpz = self.dis(self.pz) self.real = comp_fm( 'pos', self.Dpz, pz_f_idx, pz_m_idx ) # generating qzx & check negative judge if y is None: y = np.zeros((nb, self.label_dim+1)) y[:,-1] = 1 qzx_f_idx = np.where(y[:,-1]==1)[0] qzx_m_idx = np.where(y[:,-1]==0)[0] _qzx = rm.concat(self.qzx, y) self.Dqzx = self.dis(_qzx) self.fake = comp_fm( 'neg', self.Dqzx, qzx_f_idx, qzx_m_idx ) self.fake2pos = comp_fm( 'pos', self.Dqzx, qzx_f_idx, qzx_m_idx )
def forward(self, x): c1 = rm.relu(self.bn1_1(self.conv1_1(x))) t = rm.max_pool2d(c1, filter=2, stride=2) t = rm.dropout(t, 0.5) c2 = rm.relu(self.bn2_1(self.conv2_1(t))) t = rm.max_pool2d(c2, filter=2, stride=2) t = rm.dropout(t, 0.5) t = rm.relu(self.bn3_1(self.conv3_1(t))) c3 = rm.relu(self.bn3_2(self.conv3_2(t))) t = rm.max_pool2d(c3, filter=2, stride=2) t = rm.dropout(t, 0.5) t = rm.relu(self.bn4_1(self.conv4_1(t))) c4 = rm.relu(self.bn4_2(self.conv4_2(t))) t = rm.max_pool2d(c4, filter=2, stride=2) t = rm.dropout(t, 0.5) t = rm.relu(self.bn5_1(self.conv5_1(t))) t = rm.relu(self.bn5_2(self.conv5_2(t))) t = self.deconv1(t)[:, :, :c4.shape[2], :c4.shape[3]] t = rm.concat([c4, t]) t = rm.relu(self.conv6(t)) t = self.deconv2(t)[:, :, :c3.shape[2], :c3.shape[3]] t = rm.concat([c3, t]) t = rm.relu(self.conv7(t)) t = self.deconv3(t)[:, :, :c2.shape[2], :c2.shape[3]] t = rm.concat([c2, t]) t = rm.relu(self.conv8(t)) t = self.deconv4(t)[:, :, :c1.shape[2], :c1.shape[3]] t = rm.concat([c1, t]) t = rm.relu(self.conv9(t)) t = self.deconv5(t)[:, :, :c1.shape[2], :c1.shape[3]] t = rm.concat([c1, t]) t = self.conv10(t) return t
def __new__(self, x, slice_size=1, axis=1): if axis is None: axis = 1 assert len(x.shape) > 1 input_length = x.shape[axis] maxes = [] # TODO: Ensure that input_length is evenly divisible by _slice_size for u in range(input_length // slice_size): offset = u * slice_size maxes.append( rm.amax(x[:, offset:offset + slice_size], axis=axis, keepdims=True)) return rm.concat(*maxes, axis=axis)
def forward(self, x): t1 = rm.max_pool2d(x, filter=3, stride=2) t2 = rm.relu(self.batch_norm1_red(self.conv1_red(x))) t2 = rm.relu(self.batch_norm1(self.conv1(t2))) t3 = rm.relu(self.batch_norm2_red(self.conv2_red(x))) t3 = rm.relu(self.batch_norm2_1(self.conv2_1(t3))) t3 = rm.relu(self.batch_norm2_2(self.conv2_2(t3))) t3 = rm.relu(self.batch_norm2_3(self.conv2_3(t3))) return rm.concat([ t1, t2, t3 ])
def forward(self,x,action): h=self.d1(x) # h=self.r(h) # h=self.d2(h) # h=self.r(h) a = self.emb(action) a = self.r(a) a = self.ad1(a) a = self.r(a) h = rm.concat(h,a) h=self.d3(h) h=self.r(h) h=self.d4(h) return h
def forward(self, x): i = 0 t = self.base[i](x) i += 1 t = rm.relu(self.base[i](t)) i += 1 t = rm.max_pool2d(t, filter=3, stride=2, padding=1) for j in self.layer_per_block[:-1]: for k in range(j): tmp = t t = self.base[i](t) i += 1 t = rm.concat(tmp, t) t = self.base[i](t) i += 1 for j in range(self.layer_per_block[-1]): tmp = t t = self.base[i](t) i += 1 t = rm.concat(tmp, t) t = rm.average_pool2d(t, filter=7, stride=1) t = rm.flatten(t) t = self.fc(t) return t
def forward(self, x, print_parameter=False): hidden = self.input(x) if print_parameter: print('{}'.format('-' * 20)) print('check network') print(x.shape) print('{}'.format('-' * 20)) if self.dropout: hidden = rm.dropout(hidden) hidden = rm.max_pool2d(hidden, stride=1, padding=1) if print_parameter: print(hidden.shape) print('{}'.format('-' * 20)) layers = self.hidden._layers blocks = self.blocks if isinstance(self.blocks, int) else len( self.blocks) for i in range(blocks): offset = i * (self.depth * 2 + 1) for j in range(self.depth): sub = rm.leaky_relu(layers[offset + 2 * j](hidden)) if print_parameter: print('{}.{} b {}'.format(i, j, sub.shape)) sub = layers[offset + 2 * j + 1](sub) if print_parameter: print('{}.{} + {}'.format(i, j, sub.shape)) if self.dropout: sub = rm.dropout(sub) hidden = rm.concat(hidden, sub) if print_parameter: print('{}.{} = {}'.format(i, j, hidden.shape)) offset = (i + 1) * (self.depth * 2 + 1) - 1 hidden = layers[offset](hidden) if print_parameter: print('{}.{} * {}'.format(i, j, hidden.shape)) if self.dropout: if print_parameter: print('dropout') hidden = rm.dropout(hidden) hidden = rm.average_pool2d(hidden, padding=1, stride=(1, 2) if self.keep_v else 2) if print_parameter: print('{}.{} @ {}'.format(i, j, hidden.shape)) print('{}'.format('-' * 20)) x = rm.flatten(hidden) if print_parameter: print(' >>> {} prameters'.format(x.shape)) return x
def forward(self, x): layers = self.hidden._layers hidden = self.input(x) i = 0 for _ in range(self.depth): main_stream = hidden hidden = layers[i](main_stream) i += 1 hidden = rm.tanh(hidden) hidden = layers[i](hidden) i += 1 if self.dropout: hidden = rm.dropout(hidden) hidden = rm.concat(main_stream, hidden) #print(hidden.shape) return self.output(hidden)
def forward(self, x): t1 = rm.average_pool2d(x, filter=3, padding=1) t1 = rm.relu(self.batch_norm1(self.conv1(t1))) t2 = rm.relu(self.batch_norm2(self.conv2(x))) t3 = rm.relu(self.batch_norm3_1(self.conv3_1(x))) t3 = rm.relu(self.batch_norm3_2(self.conv3_2(t3))) t3 = rm.relu(self.batch_norm3_3(self.conv3_3(t3))) t4 = rm.relu(self.batch_norm4_1(self.conv4_1(x))) t4 = rm.relu(self.batch_norm4_2(self.conv4_2(t4))) t4 = rm.relu(self.batch_norm4_3(self.conv4_3(t4))) t4 = rm.relu(self.batch_norm4_4(self.conv4_4(t4))) t4 = rm.relu(self.batch_norm4_5(self.conv4_5(t4))) return rm.concat([t1, t2, t3, t4])
def forward(self, x): layers = self.hidden._layers hidden = self.input(self.active(self.input_batch(x))) for i in range(self.depth - 1): sub = self.active(layers[i * 2](hidden)) sub = layers[i * 2 + 1](sub) if self.dropout: sub = rm.dropout(sub, dropout_ratio=0.2) hidden = rm.concat(hidden, sub) if self.multi_output: layers = self.output._layers outputs = [] for i in range(self.output_shape[0]): hidden = self.active(layers[i * 2](hidden)) outputs.append(layers[i * 2 + 1](hidden)) return outputs return self.output(hidden)
def forward(self, x, y=None, eps=1e-3): # x : input data # y : one-hot label data for categorical dist. or supporting dis. # empty is not assignment # self.qzx : style z # self.rep : input data for decoding nb = len(x) # --- encoding phase --- if 0: noise = random.randn(x.size).reshape(nb, x.shape[1])*0.03 self._x = x+noise else: _x = x if self.mode=='clustering' or self.mode=='reduction': self.qzx, self.qyx = self.enc(_x) else: self.qzx = self.enc(_x) # --- decoding/reconstruction phase --- if self.mode=='clustering' or self.mode=='reduction': self.recon = self.dec(rm.concat(self.qzx, self.qyx)) else: self.recon = self.dec(self.qzx) # --- reguralization phase --- if self.mode == 'incorp_label': self._set_incorpdist(x) else: self._set_distribution(x) if self.mode == 'clustering': "categorical dist" elif self.mode == 'supervised': "" elif self.mode == 'dim_reduction': "" if self.mode == 'incorp_label': self._incorp_label(x, y, eps=eps) else: self.Dpz = self.dis(self.pz) self.Dqzx = self.dis(self.qzx) self.real = -rm.sum(rm.log( self.Dpz + eps ))/nb self.fake = -rm.sum(rm.log( 1 - self.Dqzx + eps ))/nb self.fake2pos = -rm.sum(rm.log( self.Dqzx + eps ))/nb if self.mode=='clustering' or self.mode=='reduction': _idx = np.where(y.sum(1)==1)[0] idx_ = np.where(y.sum(1)==0)[0] if len(_idx) > 0: self.Cy = self.cds(y) self.Cqyx = self.cds(self.qyx) self.Creal = -rm.sum(rm.log( self.Cy[_idx] + eps ))/len(_idx) if 0: self.Cfake = -rm.sum(rm.log( 1 - self.Cqyx[_idx] + eps ))/len(_idx) else: self.Cfake = -rm.sum(rm.log( 1 - self.Cqyx + eps ))/nb self.Cfake2 = -rm.sum(rm.log( self.Cqyx[_idx] + eps ))/len(_idx) else: self.Cfake = rm.Variable(0) self.Creal = rm.Variable(0) self.Cfake2 = rm.Variable(0) # --- sumalizing loss --- self.gan_loss = self.real + self.fake if self.mode=='clustering': if len(_idx) > 0: self.reconE = rm.mean_squared_error( self.recon[idx_], x[idx_]) else: self.reconE = rm.mean_squared_error(self.recon, x) else: self.reconE = rm.mean_squared_error(self.recon, x) self.real_count = (self.Dpz >= 0.5).sum()/nb self.fake_count = (self.Dqzx < 0.5).sum()/nb self.enc_loss = self.fake2pos if self.mode=='clustering' or self.mode=='reduction': if len(_idx) > 0: self.Creal_count = (self.Cy[_idx] >= 0.5).sum()/len(_idx) self.Cfake_count = (self.Cqyx[_idx] < 0.5).sum()/len(_idx) else: self.Creal_count = 0 self.Cfake_count = 0 self.CganE = self.Creal + self.Cfake self.CgenE = self.Cfake2 return self.recon
def func(node): return sum(rm.concat(node, axis=axis))
def func(node, x): return sum(rm.concat(node, x))
def forward(self, x): n = x.shape[0] t = x # Vgg 3rd Block t = rm.relu(self.conv3_1(t)) t = rm.relu(self.conv3_2(t)) t = rm.relu(self.conv3_3(t)) t = self.pool3(t) # Vgg 4th Block t = rm.relu(self.conv4_1(t)) t = rm.relu(self.conv4_2(t)) t = rm.relu(self.conv4_3(t)) # Normalize and compute location, confidence and priorbox aspect ratio conv4_norm = self.norm(t) conv4_norm_loc = self.conv4_3_mbox_loc(conv4_norm) conv4_norm_loc_flat = rm.flatten(conv4_norm_loc.transpose(0, 2, 3, 1)) conv4_norm_conf = self.conv4_3_mbox_conf(conv4_norm) conv4_norm_conf_flat = rm.flatten(conv4_norm_conf.transpose( 0, 2, 3, 1)) t = self.pool4(t) # Vgg 5th Block t = rm.relu(self.conv5_1(t)) t = rm.relu(self.conv5_2(t)) t = rm.relu(self.conv5_3(t)) t = self.pool5(t) # Vgg 6, 7th Block t = rm.relu(self.fc6(t)) t = rm.relu(self.fc7(t)) # Confirmed here. # Normalize and compute location, confidence and priorbox aspect ratio fc7_mbox_loc = self.fc7_mbox_loc(t) fc7_mbox_loc_flat = rm.flatten(fc7_mbox_loc.transpose(0, 2, 3, 1)) fc7_mbox_conf = self.fc7_mbox_conf(t) fc7_mbox_conf_flat = rm.flatten(fc7_mbox_conf.transpose(0, 2, 3, 1)) t = rm.relu(self.conv8_1(t)) t = rm.relu(self.conv8_2(t)) # Normalize and compute location, confidence and priorbox aspect ratio conv8_mbox_loc = self.conv8_2_mbox_loc(t) conv8_mbox_loc_flat = rm.flatten(conv8_mbox_loc.transpose(0, 2, 3, 1)) conv8_mbox_conf = self.conv8_2_mbox_conf(t) conv8_mbox_conf_flat = rm.flatten(conv8_mbox_conf.transpose( 0, 2, 3, 1)) t = rm.relu(self.conv9_1(t)) t = rm.relu(self.conv9_2(t)) # Normalize and compute location, confidence and priorbox aspect ratio conv9_mbox_loc = self.conv9_2_mbox_loc(t) conv9_mbox_loc_flat = rm.flatten(conv9_mbox_loc.transpose(0, 2, 3, 1)) conv9_mbox_conf = self.conv9_2_mbox_conf(t) conv9_mbox_conf_flat = rm.flatten(conv9_mbox_conf.transpose( 0, 2, 3, 1)) t = rm.relu(self.conv10_1(t)) t = rm.relu(self.conv10_2(t)) conv10_mbox_loc = self.conv10_2_mbox_loc(t) conv10_mbox_loc_flat = rm.flatten(conv10_mbox_loc.transpose( 0, 2, 3, 1)) conv10_mbox_conf = self.conv10_2_mbox_conf(t) conv10_mbox_conf_flat = rm.flatten( conv10_mbox_conf.transpose(0, 2, 3, 1)) t = rm.relu(self.conv10_1(t)) t = rm.relu(self.conv10_2(t)) conv11_mbox_loc = self.conv11_2_mbox_loc(t) conv11_mbox_loc_flat = rm.flatten(conv11_mbox_loc.transpose( 0, 2, 3, 1)) conv11_mbox_conf = self.conv11_2_mbox_conf(t) conv11_mbox_conf_flat = rm.flatten( conv11_mbox_conf.transpose(0, 2, 3, 1)) mbox_loc = rm.concat([ conv4_norm_loc_flat, fc7_mbox_loc_flat, conv8_mbox_loc_flat, conv9_mbox_loc_flat, conv10_mbox_loc_flat, conv11_mbox_loc_flat ]) mbox_conf = rm.concat([ conv4_norm_conf_flat, fc7_mbox_conf_flat, conv8_mbox_conf_flat, conv9_mbox_conf_flat, conv10_mbox_conf_flat, conv11_mbox_conf_flat ]) mbox_loc = mbox_loc.reshape((n, -1, 4)) mbox_conf = mbox_conf.reshape((n, -1, self.num_class)) predictions = rm.concat([mbox_loc, mbox_conf], axis=2) return predictions
def forward(self, x, action): return self._l2(rm.concat(self._l1(x), action))
def reorg(input): output1 = rm.concat(input[:, :, ::2, ::2], input[:, :, 1::2, ::2]) output2 = rm.concat(input[:, :, ::2, 1::2], input[:, :, 1::2, 1::2]) output = rm.concat(output1, output2) return output
def forward(self, x): n = x.shape[0] t = x t = self.pool3( rm.relu( self.conv3_3(rm.relu(self.conv3_2(rm.relu(self.conv3_1(t))))))) t = rm.relu( self.conv4_3(rm.relu(self.conv4_2(rm.relu(self.conv4_1(t)))))) # Normalize and compute location, confidence and priorbox aspect ratio conv4_norm = self.norm(t) #conv4_norm = t conv4_norm_loc = self.conv4_3_mbox_loc(conv4_norm) conv4_norm_loc_flat = rm.flatten(conv4_norm_loc) conv4_norm_conf = self.conv4_3_mbox_conf(conv4_norm) conv4_norm_conf_flat = rm.flatten(conv4_norm_conf) conv4_priorbox = self.conv4_3_priorbox(conv4_norm) t = self.pool4(t) t = self.pool5( rm.relu( self.conv5_3(rm.relu(self.conv5_2(rm.relu(self.conv5_1(t))))))) t = rm.relu(self.fc6(t)) t = rm.relu(self.fc7(t)) # Normalize and compute location, confidence and priorbox aspect ratio fc7_mbox_loc = self.fc7_mbox_loc(t) fc7_mbox_loc_flat = rm.flatten(fc7_mbox_loc) fc7_mbox_conf = self.fc7_mbox_conf(t) fc7_mbox_conf_flat = rm.flatten(fc7_mbox_conf) fc7_priorbox = self.fc7_priorbox(t) t = rm.relu(self.conv8_2(rm.relu(self.conv8_1(t)))) # Normalize and compute location, confidence and priorbox aspect ratio conv8_mbox_loc = self.conv8_2_mbox_loc(t) conv8_mbox_loc_flat = rm.flatten(conv8_mbox_loc) conv8_mbox_conf = self.conv8_2_mbox_conf(t) conv8_mbox_conf_flat = rm.flatten(conv8_mbox_conf) conv8_priorbox = self.conv8_2_priorbox(t) t = rm.relu(self.conv9_2(rm.relu(self.conv9_1(t)))) # Normalize and compute location, confidence and priorbox aspect ratio conv9_mbox_loc = self.conv9_2_mbox_loc(t) conv9_mbox_loc_flat = rm.flatten(conv9_mbox_loc) conv9_mbox_conf = self.conv9_2_mbox_conf(t) conv9_mbox_conf_flat = rm.flatten(conv9_mbox_conf) conv9_priorbox = self.conv9_2_priorbox(t) t = rm.relu(self.conv10_2(rm.relu(self.conv10_1(t)))) conv10_mbox_loc = self.conv10_2_mbox_loc(t) conv10_mbox_loc_flat = rm.flatten(conv10_mbox_loc) conv10_mbox_conf = self.conv10_2_mbox_conf(t) conv10_mbox_conf_flat = rm.flatten(conv10_mbox_conf) conv10_priorbox = self.conv10_2_priorbox(t) t = rm.average_pool2d(t) t = rm.flatten(t) pool11_mbox_loc_flat = self.pool11_mbox_loc(t) pool11_mbox_conf_flat = self.pool11_mbox_conf(t) pool11_reshaped = t.reshape((t.shape[0], 256, 1, 1)) pool11_priorbox = self.pool11_priorbox(pool11_reshaped) mbox_loc = rm.concat([ conv4_norm_loc_flat, fc7_mbox_loc_flat, conv8_mbox_loc_flat, conv9_mbox_loc_flat, conv10_mbox_loc_flat, pool11_mbox_loc_flat ]) mbox_conf = rm.concat([ conv4_norm_conf_flat, fc7_mbox_conf_flat, conv8_mbox_conf_flat, conv9_mbox_conf_flat, conv10_mbox_conf_flat, pool11_mbox_conf_flat ]) mbox_priorbox = np.concatenate([ conv4_priorbox, fc7_priorbox, conv8_priorbox, conv9_priorbox, conv10_priorbox, pool11_priorbox ], axis=1) num_boxes = mbox_loc.shape[-1] // 4 mbox_loc = mbox_loc.reshape((n, 4, num_boxes)) mbox_conf = mbox_conf.reshape((n, self.num_class, num_boxes)) predictions = rm.concat([ mbox_loc, mbox_conf, np.broadcast_to(mbox_priorbox.transpose((0, 2, 1)), (mbox_conf.shape[0], mbox_priorbox.shape[2], mbox_priorbox.shape[1])) ]) return predictions