Exemple #1
0
def _fcn16s_logits(ftmps, hparams, weights, layers, num_classes, logits_shape,
                   init_weights):
    pool4_proj = project_layer(layers["pool4"],
                               hparams=hparams,
                               weights=weights,
                               out_depth=num_classes,
                               name="pool4_proj",
                               init_weights=init_weights)
    out_up2x = upsample_layer(ftmps,
                              hparams,
                              weights=weights,
                              upsample_factor=2,
                              output_shape=tf.shape(pool4_proj),
                              name="out_up2x",
                              init_weights=init_weights)

    fused_pool4 = tf.add(pool4_proj, out_up2x, "fused_pool4")

    fused_pool4_up16x = upsample_layer(fused_pool4,
                                       hparams,
                                       weights=weights,
                                       upsample_factor=16,
                                       output_shape=logits_shape,
                                       name="fused_pool4_up16x",
                                       init_weights=init_weights)
    return fused_pool4_up16x
Exemple #2
0
def _fcn8s_logits(ftmps, hparams, weights, layers, num_classes, logits_shape,
                  init_weights):
    pool4 = layers["pool4"]
    if hparams.fcn8s_oneshot == True:
        pool4 = tf.multiply(pool4, 0.01)
    pool4_proj = project_layer(pool4,
                               hparams=hparams,
                               weights=weights,
                               out_depth=num_classes,
                               name="pool4_proj",
                               init_weights=init_weights)

    pool3 = layers["pool3"]
    if hparams.fcn8s_oneshot == True:
        pool3 = tf.multiply(pool3, 0.0001)
    pool3_proj = project_layer(pool3,
                               hparams=hparams,
                               weights=weights,
                               out_depth=num_classes,
                               name="pool3_proj",
                               init_weights=init_weights)

    out_up2x = upsample_layer(ftmps,
                              hparams,
                              weights=weights,
                              upsample_factor=2,
                              output_shape=tf.shape(pool4_proj),
                              name="out_up2x",
                              init_weights=init_weights)

    fused_pool4 = tf.add(pool4_proj, out_up2x, "fused_pool4")

    fused_pool4_up2x = upsample_layer(fused_pool4,
                                      hparams,
                                      weights=weights,
                                      upsample_factor=2,
                                      output_shape=tf.shape(pool3_proj),
                                      name="fused_pool4_up2x",
                                      init_weights=init_weights)

    fused_pool3 = tf.add(pool3_proj, fused_pool4_up2x, "fused_pool3")

    fused_pool3_up8x = upsample_layer(fused_pool3,
                                      hparams,
                                      weights=weights,
                                      upsample_factor=8,
                                      output_shape=logits_shape,
                                      name="fused_pool3_up8x",
                                      init_weights=init_weights)
    return fused_pool3_up8x
Exemple #3
0
def yolo_v3(inputs):

    # Darknet
    route_1, route_2, inputs = darknet.darknet(inputs)


    # Large detections
    inputs = layers.conv_layer(name="conv_00", inputs=inputs, filters=512, kernel_size=1)
    inputs = layers.conv_layer(name="conv_01", inputs=inputs, filters=1024, kernel_size=3)
    inputs = layers.conv_layer(name="conv_02", inputs=inputs, filters=512, kernel_size=1)
    inputs = layers.conv_layer(name="conv_03", inputs=inputs, filters=1024, kernel_size=3)   
    inputs = layers.conv_layer(name="conv_04", inputs=inputs, filters=512, kernel_size=1)
    
    large_detections = layers.conv_layer(name="conv_05", inputs=inputs, filters=1024, kernel_size=3)
    large_detections = layers.conv_layer(name="conv_06", inputs=large_detections, filters=3*(NUM_CLASSES+5), kernel_size=1, batch_normalize=False, activation=False)

    inputs = layers.conv_layer(name="conv_07", inputs=inputs, filters=256, kernel_size=1)
    inputs = layers.upsample_layer(name="upsample_0", inputs=inputs)
    
    inputs = layers.route_layer(name="route_0", inputs=inputs, route=route_2)


    # Medium detections
    inputs = layers.conv_layer(name="conv_08", inputs=inputs, filters=256, kernel_size=1)
    inputs = layers.conv_layer(name="conv_09", inputs=inputs, filters=512, kernel_size=3)
    inputs = layers.conv_layer(name="conv_10", inputs=inputs, filters=256, kernel_size=1)
    inputs = layers.conv_layer(name="conv_11", inputs=inputs, filters=512, kernel_size=3)   
    inputs = layers.conv_layer(name="conv_12", inputs=inputs, filters=256, kernel_size=1)

    medium_detections = layers.conv_layer(name="conv_13", inputs=inputs, filters=512, kernel_size=3)
    medium_detections = layers.conv_layer(name="conv_14", inputs=medium_detections, filters=3*(NUM_CLASSES+5), kernel_size=1, batch_normalize=False, activation=False)

    inputs = layers.conv_layer(name="conv_15", inputs=inputs, filters=128, kernel_size=1)
    inputs = layers.upsample_layer(name="upsample_1", inputs=inputs)

    inputs = layers.route_layer(name="route_1", inputs=inputs, route=route_1)


    # Small detections
    inputs = layers.conv_layer(name="conv_16", inputs=inputs, filters=128, kernel_size=1)
    inputs = layers.conv_layer(name="conv_17", inputs=inputs, filters=256, kernel_size=3)
    inputs = layers.conv_layer(name="conv_18", inputs=inputs, filters=128, kernel_size=1)
    inputs = layers.conv_layer(name="conv_19", inputs=inputs, filters=256, kernel_size=3)   
    inputs = layers.conv_layer(name="conv_20", inputs=inputs, filters=128, kernel_size=1)

    small_detections = layers.conv_layer(name="conv_21", inputs=inputs, filters=256, kernel_size=3)
    small_detections = layers.conv_layer(name="conv_22", inputs=small_detections, filters=3*(NUM_CLASSES+5), kernel_size=1, batch_normalize=False, activation=False)

    return [small_detections, medium_detections, large_detections]
Exemple #4
0
def _fcn32s_logits(ftmps, hparams, weights, layers, num_classes, logits_shape,
                   init_weights):
    out_up32x = upsample_layer(ftmps,
                               hparams,
                               weights=weights,
                               upsample_factor=32,
                               output_shape=logits_shape,
                               name="out_up32x",
                               init_weights=init_weights)
    return out_up32x
Exemple #5
0
def Yolov3_Tiny(inputs, cfg_file="../cfg/yolov3-depth-tiny.cfg"):
    blocks = parse_cfg(cfg_file)
    # print(blocks)
    x, layers, outputs = inputs, [], []
    weights_ptr = 0
    config = {}
    input_dims = 416

    for i, block in enumerate(blocks):
        block_type = block["type"]
        # print("{} {}".format(i-1, block_type))
        # print("Input shape: ", x.shape)
        if block_type == "convolutional":
            x, layers, weights_ptr = conv_layer(x, block, layers, weights_ptr)

        elif block_type == "maxpool":
            x, layers = maxpool_layer(x, block, layers)

        elif block_type == "upsample":
            x, layers = upsample_layer(x, block, layers)

        elif block_type == "route":
            x, layers = route_layer(x, block, layers)

        elif block_type == "yolo":
            x, layers, outputs = yolo_layer(x, block, layers, outputs,
                                            input_dims)

        elif block_type == "convolutional_transpose":
            x, layers = conv_transpose_layer(x, block, layers)

        elif block_type == "residual":
            x, layers = residual_layer(x, block, layers)

        # print("Output shape: ", x.shape)
        # print("")
    # output_layers = [layers[i - 1] for i in range(len(layers)) if layers[i] is None]

    outputs = tf.keras.layers.Concatenate(axis=1)(outputs)
    # x = tf.sigmoid(x)

    # print(x.shape)

    # Run NMS
    # outputs = non_maximum_suppression(outputs, confidence=0.5, num_classes=80, nms_threshold=0.5)

    return (outputs, x)  # outputs: yolo bounding box, x: depth