deephealthproject / eddl

European Distributed Deep Learning (EDDL) library. A general-purpose library initially developed to cover deep learning needs in healthcare use cases within the DeepHealth project.
https://deephealthproject.github.io/eddl/
MIT License
34 stars 10 forks source link

removeLayer() causes vector subscript out of range error #258

Closed MicheleCancilla closed 3 years ago

MicheleCancilla commented 3 years ago

Describe the bug Removing the last layer of Net causes vector subscript out of range debug assertion error in debug on Visual Studio. The error occurs on net_build.cpp: https://github.com/deephealthproject/eddl/blob/6759e7976f045e3cd10e43a3f23a9be8e4880562/src/net/net_build.cpp#L61

The last layer apparently has empty child vector, so layers[j]->child[0] causes out of range error.

To Reproduce Steps to reproduce the behavior:

  1. Run onnx_export to create the "trained_model.onnx" file
  2. Edit the file 3_onnx_import_net_from_file.cpp adding the removeLayer of last softmax:
    Net* net = import_net_from_onnx_file(path, DEV_CPU);
    removeLayer(net, "softmax6");
    // Build model
    build(net,
          rmsprop(0.01), // Optimizer
          {"softmax_cross_entropy"}, // Losses
          {"categorical_accuracy"}, // Metrics
          CS_GPU({1}, "low_mem"), // one GPU
          //CS_CPU(), // CPU with maximum threads availables
          false
    );
  3. Debug the example onnx_import
RParedesPalacios commented 3 years ago

Here it is important to decide which layers are going to be the output of the network. If you remove the softmax but still pretend to build it with some loss and metrics associated... it has non sense

RParedesPalacios commented 3 years ago

Let me work on this and i will provide a way of doing

RParedesPalacios commented 3 years ago

Check 3_onnx_import_net_from_file.cpp in develop branch