Ejemplo n.º 1
0
def parse_net(num_layers, cfg, weights):
    net = None
    counters = {}
    stack = []
    cfg_walker = CFGReader(cfg)
    weights_walker = WeightsReader(weights)
    output_index = []

    for ith, layer in enumerate(cfg_walker):
        if ith > num_layers and num_layers > 0:
            break

        layer_name = layer['name']
        counters.setdefault(layer_name, 0)
        counters[layer_name] += 1

        scope = "{}{}{}".format(args.prefix, layer['name'],
                                counters[layer_name])

        net = get_cfg_layer(net,
                            layer_name,
                            layer,
                            weights_walker,
                            stack,
                            output_index,
                            scope=scope)

        stack.append(net)
        print(ith, net)

    for ind in output_index:
        print('Output layer:', stack[ind])

    return output_index
Ejemplo n.º 2
0
def parse_net(num_layers,
              cfg,
              weights,
              training=False,
              const_inits=True,
              verbose=True):
    net = None
    counters = {}
    stack = []
    cfg_walker = CFGReader(cfg)
    weights_walker = WeightsReader(weights)
    output_index = []
    num_layers = int(num_layers)
    print('len')
    print(len(weights_walker.transpose.flat))
    for ith, layer in enumerate(cfg_walker):
        if ith > num_layers and num_layers > 0:
            break
        layer_name = layer['name']
        counters.setdefault(layer_name, 0)
        counters[layer_name] += 1
        scope = "{}{}{}".format(args.prefix, layer['name'],
                                counters[layer_name])
        net = get_cfg_layer(net,
                            layer_name,
                            layer,
                            weights_walker,
                            stack,
                            output_index,
                            scope,
                            training=training,
                            const_inits=const_inits,
                            verbose=verbose)
        # Exclude `net` layer from stack (for correct layer indexing)
        # See https://github.com/jinyu121/DW2TF/issues/30
        # See https://github.com/AlexeyAB/darknet/issues/487#issuecomment-374902735
        if layer['name'] != 'net':
            stack.append(net)
        if verbose:
            print(ith, net)

    if verbose:
        for ind in output_index:
            print("=> Output layer: ", stack[ind])
Ejemplo n.º 3
0
def parse_net(num_layers,
              cfg,
              weights,
              training=False,
              const_inits=True,
              verbose=True):
    net = None
    counters = {}
    stack = []
    cfg_walker = CFGReader(cfg)
    weights_walker = WeightsReader(weights)
    output_index = []
    num_layers = int(num_layers)

    for ith, layer in enumerate(cfg_walker):
        if ith > num_layers and num_layers > 0:
            break
        layer_name = layer['name']
        counters.setdefault(layer_name, 0)
        counters[layer_name] += 1
        scope = "{}{}{}".format(args.prefix, layer['name'],
                                counters[layer_name])
        net = get_cfg_layer(net,
                            layer_name,
                            layer,
                            weights_walker,
                            stack,
                            output_index,
                            scope,
                            training=training,
                            const_inits=const_inits,
                            verbose=verbose)
        stack.append(net)
        if verbose:
            print(ith, net)

    if verbose:
        for ind in output_index:
            print("=> Output layer: ", stack[ind])