Пример #1
0
def build_graph():
    input_image = tf.placeholder(tf.float32, shape=[None, None, None, 3], name='image')
    input_label = tf.placeholder(tf.int32, shape=[None, 1], name='labels')
    input_bbox_targets = tf.placeholder(tf.float32, shape=[None, 4], name='gt_boxes')
    input_bbox_inside_weights = tf.placeholder(tf.float32, shape=[None, 4], name="bbox_inside_weights")
    input_bbox_outside_weights = tf.placeholder(tf.float32, shape=[None, 4], name='bbox_outside_weights')
    learing_rate = tf.placeholder(tf.float32)

    cnn_layers = ResNet()
    rnn_layers = Lstm()

    x = input_image
    x = cnn_layers.build(x, True)
    x = rnn_layers.build(x, 512,128, 512)

    ########################
    #   rpn cls score
    ########################

    y = fc_layer(x, 512, 10 * 2, "fc_rpn_cls")
    dims = tf.shape(y)
    cls_prob = tf.reshape(tf.nn.softmax(tf.reshape(y, [-1, 2])),
                      [dims[0], dims[1], -1, 2])

    #########################
    #   rpn bbox pred
    #########################
    box_pred = fc_layer(x, 512, 10 * 4, "fc_rpn_pred")

    loss_layer = Loss()
    output_loss ,cls_loss,box_loss = loss_layer.build(y,box_pred,input_label,input_bbox_targets,input_bbox_inside_weights,input_bbox_outside_weights)
    train_step = tf.train.AdamOptimizer(learing_rate).minimize(output_loss)

    return [train_step,output_loss,learing_rate,input_image,
            input_label,input_bbox_targets,input_bbox_inside_weights,input_bbox_outside_weights,cls_prob,box_pred,cls_loss,box_loss]
Пример #2
0
def build_graph():
    input_image = tf.placeholder(tf.float32,
                                 shape=[None, None, None, 3],
                                 name='image')
    cnn_layers = ResNet()
    rnn_layers = Lstm()

    x = input_image
    x = cnn_layers.build(x, True)
    x = rnn_layers.build(x, 512, 128, 512)

    ########################
    #   rpn cls score
    ########################

    y = fc_layer(x, 512, 10 * 2, "fc_rpn_cls")
    dims = tf.shape(y)
    cls_prob = tf.reshape(tf.nn.softmax(tf.reshape(y, [-1, 2])),
                          [dims[0], dims[1], -1, 2])

    #########################
    #   rpn bbox pred
    #########################
    box_pred = fc_layer(x, 512, 10 * 4, "fc_rpn_pred")

    return [input_image, cls_prob, box_pred]
Пример #3
0
class Inference:
    def __init__(self):
        self.net = ResNet(inference_mode=True)
        self.net.build(input_shape=(None, *IMAGE_SIZE, CHANNELS))
        self.net.load_weights(PATH_TO_MODEL_WEIGHT)
        self.net.summary()

        self.dataset = DataController(PATH_TO_TEST_DATA, True, draw_cloud=True)
        self.data_generator = self.dataset.get_eval_data_generator(
            shuffle=True)

    def __call__(self):
        for images, gt_labels in self.data_generator:
            scores = tf.nn.softmax(self.net(images)).numpy()
            for i in range(INFER_BATCH_SIZE):
                label = int(scores[i][0] < scores[i][1])
                yield 'ALERT' if label else 'PASS'
Пример #4
0
def main():
    if VISUALIZATION:
        window_manager = VisualManager('eval')

    dataset = DataController(PATH_TO_TEST_DATA, inference_mode=True)
    measure = YieldMeasure()
    data_generator = dataset.get_eval_data_generator(shuffle=True)

    net = ResNet(inference_mode=True)
    net.build(input_shape=(None, *IMAGE_SIZE, CHANNELS))
    net.load_weights(PATH_TO_MODEL_WEIGHT)
    net.summary()

    inf_time = 0
    inf_num = 0

    for images, gt_labels in data_generator:
        gt_labels = gt_labels.numpy()
        t0 = time()
        pred_labels = tf.nn.softmax(
            net(images)).numpy().argmax(axis=1).astype('int32')
        inf_time += (time() - t0)
        inf_num += 1

        measure.append(gt_labels, pred_labels)

        if VISUALIZATION:
            visual_batch = []
            for i in range(INFER_BATCH_SIZE):
                frame = (images[i] * 255).numpy().astype('uint8')
                window_manager.draw_annotations(frame, pred_labels[i],
                                                gt_labels[i],
                                                dataset.invert_class_dict)
                visual_batch.append(frame)
            window_manager.desktop_show(concatenate(visual_batch, axis=1), 0)
    measure.show_rating()
    print(f"Median inference time: {(inf_time / inf_num) * 1000:.1f} ms")