예제 #1
0
    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)
        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)

        ##### pretraining layer
        h = self.conv23(h)
        h = rm.average_pool2d(h,
                              filter=(h.shape[-1], h.shape[-1]),
                              stride=(1, 1),
                              padding=(0, 0))

        y = rm.reshape(h, (x.shape[0], -1))

        return y
 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):
     layers = self.hidden._layers
     for i in range(self.depth):
         if self.batch_normal:
             x = layers[i * 4](x)
             x = rm.relu(layers[i * 4 + 1](x))
             x = layers[i * 4 + 2](x)
             x = rm.relu(layers[i * 4 + 3](x))
         else:
             x = rm.relu(layers[i * 2](x))
             #print(x.shape)
             x = rm.relu(layers[i * 2 + 1](x))
             #print(x.shape)
         if i == self.depth - 1:
             x = rm.average_pool2d(x, stride=2, padding=(1, 1))
         else:
             x = rm.max_pool2d(x, stride=2, padding=(1, 1))
         #print(x.shape)
     x = rm.flatten(x)
     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
예제 #4
0
 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
예제 #5
0
    def forward(self, x):
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)

        x = rm.average_pool2d(x, filter=(x.shape[2], x.shape[3]))
        x = self.flat(x)
        x = self.fc(x)

        return x
예제 #6
0
    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])
예제 #7
0
 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
예제 #8
0
    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