happynear / caffe-windows

Configure Caffe in one hour for Windows users.
Other
1.32k stars 650 forks source link

after deleting a Net instance, the GPU memory is not released #327

Open mmchen88 opened 4 years ago

mmchen88 commented 4 years ago

This is my construction of Classifier: Classifier::Classifier(const std::string& model_file, const std::string& trained_file) {

ifdef CPU_ONLY

Caffe::set_mode(Caffe::CPU);

else

Caffe::set_mode(Caffe::GPU);

endif

/* Load the network. */
net_.reset(new Net<float>(model_file, TEST));
net_->CopyTrainedLayersFrom(trained_file);

CHECK_EQ(net_->num_inputs(), 1) << "Network should have exactly one input.";
CHECK_EQ(net_->num_outputs(), 1) << "Network should have exactly one output.";

Blob<float>* input_layer = net_->input_blobs()[0];
num_channels_ = input_layer->channels();
CHECK(num_channels_ == 3 || num_channels_ == 1)
    << "Input layer should have 1 or 3 channels.";
input_geometry_ = cv::Size(input_layer->width(), input_layer->height());

} and,this is my test code: Classifier* cnn_1 = new Classifier(lenet_model_file, lenet_trained_file); delete cnn_1; the problem is after deleting cnn_1, the memory of GPU is not released. Please tell me how to release the memory of GPU caused by loading the model.