Skip to content

Darknet importer: unable to import clasification configuration file darknet19.cfg #16623

Closed

Description

@isra60

Using one of the cfg file from darknet repo. (darknet-19 for classification not detection).

https://github.com/AlexeyAB/darknet/blob/master/cfg/darknet19.cfg

opencv/modules/dnn/src/darknet/darknet_io.cpp:678: error: (-212:Parsing error) Unknown layer type: sse in function 'ReadDarknetFromCfgStream'

Seems to be in cost layer...

[cost]
type=sse

Activity

  1. dkurt commented on Feb 20, 2020

    @dkurt
    Member

    @isra60, try to remove this layer - it's training only.

  2. isra60 commented on Feb 20, 2020

    @isra60
    Author

    I remove it but then when I try

        cv::dnn::Net net = cv::dnn::readNet(modelConfiguration, modelWeights);
    
        net.setPreferableBackend(GetAnalyticsParameters()->GetDNNBackend());
        net.setPreferableTarget(GetAnalyticsParameters()->GetDNNTarget());
    
        std::cout << net.dump() << std::endl;
    

    where DNN target and backend are CUDA

    terminate called after throwing an instance of 'cv::Exception'
    what(): OpenCV(4.2.0-dev) /opencv/modules/dnn/src/dnn.cpp:3781: error: (-2:Unspecified error) Requested set input in function 'dump'

  3. dkurt commented on Feb 20, 2020

    @dkurt
    Member

    @isra60, as pointed in the error message, you should set some input before dump

    We already fixed that for future releases in #16516

  4. isra60 commented on Feb 20, 2020

    @isra60
    Author

    but.... I'm using master branch (4.2.0.-dev) this still should be happen???

  5. dkurt commented on Feb 20, 2020

    @dkurt
    Member

    Cannot reproduce it with weights from https://pjreddie.com/media/files/darknet19.weights and .cfg from issue description (3.4 branch):

    import cv2 as cv
    
    net = cv.dnn.readNet('darknet19.cfg', 'darknet19.weights')
    print(net.dump())
    output
    digraph G {
    	"conv_0" [label="conv_0\nConvolution\nkernel_size : 3\lstride : 1\lpad : 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_0" [label="bn_0\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_1" [label="relu_1\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"pool_1" [label="pool_1\nPooling\nkernel_size : 2\lstride : 2\lpad (HxW): (0, 1) x (0, 1)\lpool: max\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_2" [label="conv_2\nConvolution\nkernel_size : 3\lstride : 1\lpad : 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_2" [label="bn_2\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_3" [label="relu_3\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"pool_3" [label="pool_3\nPooling\nkernel_size : 2\lstride : 2\lpad (HxW): (0, 1) x (0, 1)\lpool: max\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_4" [label="conv_4\nConvolution\nkernel_size : 3\lstride : 1\lpad : 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_4" [label="bn_4\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_5" [label="relu_5\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_5" [label="conv_5\nConvolution\nkernel_size : 1\lstride : 1\lpad : 0\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_5" [label="bn_5\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_6" [label="relu_6\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_6" [label="conv_6\nConvolution\nkernel_size : 3\lstride : 1\lpad : 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_6" [label="bn_6\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_7" [label="relu_7\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"pool_7" [label="pool_7\nPooling\nkernel_size : 2\lstride : 2\lpad (HxW): (0, 1) x (0, 1)\lpool: max\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_8" [label="conv_8\nConvolution\nkernel_size : 3\lstride : 1\lpad : 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_8" [label="bn_8\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_9" [label="relu_9\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_9" [label="conv_9\nConvolution\nkernel_size : 1\lstride : 1\lpad : 0\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_9" [label="bn_9\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_10" [label="relu_10\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_10" [label="conv_10\nConvolution\nkernel_size : 3\lstride : 1\lpad : 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_10" [label="bn_10\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_11" [label="relu_11\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"pool_11" [label="pool_11\nPooling\nkernel_size : 2\lstride : 2\lpad (HxW): (0, 1) x (0, 1)\lpool: max\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_12" [label="conv_12\nConvolution\nkernel_size : 3\lstride : 1\lpad : 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_12" [label="bn_12\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_13" [label="relu_13\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_13" [label="conv_13\nConvolution\nkernel_size : 1\lstride : 1\lpad : 0\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_13" [label="bn_13\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_14" [label="relu_14\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_14" [label="conv_14\nConvolution\nkernel_size : 3\lstride : 1\lpad : 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_14" [label="bn_14\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_15" [label="relu_15\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_15" [label="conv_15\nConvolution\nkernel_size : 1\lstride : 1\lpad : 0\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_15" [label="bn_15\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_16" [label="relu_16\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_16" [label="conv_16\nConvolution\nkernel_size : 3\lstride : 1\lpad : 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_16" [label="bn_16\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_17" [label="relu_17\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"pool_17" [label="pool_17\nPooling\nkernel_size : 2\lstride : 2\lpad (HxW): (0, 1) x (0, 1)\lpool: max\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_18" [label="conv_18\nConvolution\nkernel_size : 3\lstride : 1\lpad : 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_18" [label="bn_18\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_19" [label="relu_19\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_19" [label="conv_19\nConvolution\nkernel_size : 1\lstride : 1\lpad : 0\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_19" [label="bn_19\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_20" [label="relu_20\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_20" [label="conv_20\nConvolution\nkernel_size : 3\lstride : 1\lpad : 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_20" [label="bn_20\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_21" [label="relu_21\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_21" [label="conv_21\nConvolution\nkernel_size : 1\lstride : 1\lpad : 0\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_21" [label="bn_21\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_22" [label="relu_22\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_22" [label="conv_22\nConvolution\nkernel_size : 3\lstride : 1\lpad : 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"bn_22" [label="bn_22\nBatchNorm\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"relu_23" [label="relu_23\nReLU\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"conv_23" [label="conv_23\nConvolution\nkernel_size : 1\lstride : 1\lpad : 0\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"avgpool_24" [label="avgpool_24\nPooling\npool: ave\lglobal_pooling: 1\lOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    	"softmax_25" [label="softmax_25\nSoftmax\nOCV/CPU\n" fillcolor="#ffffb3" style=filled shape=box]
    
    	"_input" -> "conv_0"
    	"conv_0" -> "bn_0"
    	"bn_0" -> "relu_1"
    	"relu_1" -> "pool_1"
    	"pool_1" -> "conv_2"
    	"conv_2" -> "bn_2"
    	"bn_2" -> "relu_3"
    	"relu_3" -> "pool_3"
    	"pool_3" -> "conv_4"
    	"conv_4" -> "bn_4"
    	"bn_4" -> "relu_5"
    	"relu_5" -> "conv_5"
    	"conv_5" -> "bn_5"
    	"bn_5" -> "relu_6"
    	"relu_6" -> "conv_6"
    	"conv_6" -> "bn_6"
    	"bn_6" -> "relu_7"
    	"relu_7" -> "pool_7"
    	"pool_7" -> "conv_8"
    	"conv_8" -> "bn_8"
    	"bn_8" -> "relu_9"
    	"relu_9" -> "conv_9"
    	"conv_9" -> "bn_9"
    	"bn_9" -> "relu_10"
    	"relu_10" -> "conv_10"
    	"conv_10" -> "bn_10"
    	"bn_10" -> "relu_11"
    	"relu_11" -> "pool_11"
    	"pool_11" -> "conv_12"
    	"conv_12" -> "bn_12"
    	"bn_12" -> "relu_13"
    	"relu_13" -> "conv_13"
    	"conv_13" -> "bn_13"
    	"bn_13" -> "relu_14"
    	"relu_14" -> "conv_14"
    	"conv_14" -> "bn_14"
    	"bn_14" -> "relu_15"
    	"relu_15" -> "conv_15"
    	"conv_15" -> "bn_15"
    	"bn_15" -> "relu_16"
    	"relu_16" -> "conv_16"
    	"conv_16" -> "bn_16"
    	"bn_16" -> "relu_17"
    	"relu_17" -> "pool_17"
    	"pool_17" -> "conv_18"
    	"conv_18" -> "bn_18"
    	"bn_18" -> "relu_19"
    	"relu_19" -> "conv_19"
    	"conv_19" -> "bn_19"
    	"bn_19" -> "relu_20"
    	"relu_20" -> "conv_20"
    	"conv_20" -> "bn_20"
    	"bn_20" -> "relu_21"
    	"relu_21" -> "conv_21"
    	"conv_21" -> "bn_21"
    	"bn_21" -> "relu_22"
    	"relu_22" -> "conv_22"
    	"conv_22" -> "bn_22"
    	"bn_22" -> "relu_23"
    	"relu_23" -> "conv_23"
    	"conv_23" -> "avgpool_24"
    	"avgpool_24" -> "softmax_25"
    }
    
  6. isra60 commented on Feb 21, 2020

    @isra60
    Author

    OK, seems working for me too (My repo was not fully updated sorry).

    Is there any tutorial of how to process the detections from the net and also how to prepare the input blob??

  7. dkurt commented on Feb 21, 2020

    @dkurt
    Member

    Can we close this issue?

  8. alalek commented on Feb 21, 2020

    @alalek
    Member

    I believe we can try to improve DarkNet importer to ignore "Cost" training-only layers.
    Any thoughts?

  9. ashishkrshrivastava commented on Feb 22, 2020

    @ashishkrshrivastava
    Contributor

    @alalek , Maybe either setting "Identity" layer for "Cost" layer just like "Dropout" or ignoring while parsing would work ?

  10. dkurt commented on Feb 22, 2020

    @dkurt
    Member

    That's good idea

  11. ashishkrshrivastava commented on Feb 22, 2020

    @ashishkrshrivastava
    Contributor

    @alalek , @dkurt
    while parsing, if we set cost as identity layer

    [cost]
    type=sse
    

    the parameter type is interpreted as layer type. producing error.
    darknet_io.cpp:762: error: (-212:Parsing error) Unknown layer type: sse in function 'ReadDarknetFromCfgStream'
    Because here we are storing layer type with key "type".

    else {
    // read section
    read_net = false;
    ++layers_counter;
    const size_t layer_type_size = line.find("]") - 1;
    CV_Assert(layer_type_size < line.size());
    std::string layer_type = line.substr(1, layer_type_size);
    net->layers_cfg[layers_counter]["type"] = layer_type;

    And here "type" parameter is getting stored with key "type" itself.
    default:
    // read entry
    const size_t separator_index = line.find('=');
    CV_Assert(separator_index < line.size());
    if (separator_index != std::string::npos) {
    std::string name = line.substr(0, separator_index);
    std::string value = line.substr(separator_index + 1, line.size() - (separator_index + 1));
    name = escapeString(name);
    value = escapeString(value);
    if (name.empty() || value.empty()) continue;
    if (read_net)
    net->net_cfg[name] = value;
    else
    net->layers_cfg[layers_counter][name] = value;

    So ignoring while parsing until "[" i.e. next layer is seen is better option ? Am I right ?

  12. dkurt commented on Feb 22, 2020

    @dkurt
    Member

    There are just three entries of "type" so we probably can replace it to something like "layer_type" to not to mix with "type" as layer attribute.

  13. ashishkrshrivastava commented on Feb 23, 2020

    @ashishkrshrivastava
    Contributor

    Thanks, got it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions