Ask Your Question
0

Unknown type "CudaLong" of torch class "torch.CudaLongTensor" in parseTorchType

asked 2017-05-17 11:10:38 -0600

anomaly_ gravatar image

I have a trained torch model that I am trying to import in OpenCV. Upon importing the model by

dnn::Net net = dnn::readNetFromTorch(modelFile);

I get the following error:

OpenCV Error: The function/feature is not implemented (Unknown type "CudaLong" of torch class "torch.CudaLongTensor") in parseTorchType, file /home/anomaly_/opencv-base/opencv_contrib/modules/dnn/src/torch/torch_importer.cpp, line 213 terminate called after throwing an instance of 'cv::Exception' what(): /home/anomaly_/opencv-base/opencv_contrib/modules/dnn/src/torch/torch_importer.cpp:213: error: (-213) Unknown type "CudaLong" of torch class "torch.CudaLongTensor" in function parseTorchType

Why do I get this error? Is it because of my trained model? What should I do so that my model is successfully imported?

I am using the latest opencv and opencv_contrib module.

edit retag flag offensive close merge delete

Comments

Hello, I did as told, and saved the model in CPU mode. But, that error went away, and a new one came Unknown nn class "nn.LogSoftMax" in function readTorchObject I assume this class is not yet supported yet. Can you provide me an alternative?

anomaly_ gravatar imageanomaly_ ( 2017-05-24 05:30:48 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-05-24 13:12:12 -0600

dkurtaev gravatar image

@anomaly_, I'm sorry. Some problems with website and my answers gone. Firstly, I have recommended you to convert your model to CPU mode by net = net:float(). For solve issue with LogSoftMax you could try to remove this layer or replace it to Identity. It's correct because LogSoftMax is a monotonic function. It means that for all A > B: LogSoftMax(A) > LogSoftMax(B). So for model deployment you can just use data from layer before LogSoftMax. Moreover it's better for efficiency.

edit flag offensive delete link more

Comments

Thanks @dkurtaev, but I will be glad if you could help me out a bit more. I understand that LogSoftMax can be replaced by Identity, but that can be done only in the eval mode right? We will need to have the LogSoftMax function during training. So, how do I modify the layers on the basis of which mode the model is working in? If I simply remove the softmax function or replace it with identity, the model won't converge.

anomaly_ gravatar imageanomaly_ ( 2017-05-25 01:08:33 -0600 )edit

You are right, but you can do it just for run your model using OpenCV. Train model in Torch as usual but save without LogSoftMax for evaluating needs. By the way, do you remember that OpenCV doesn't provide networks training, only evaluation?

dkurtaev gravatar imagedkurtaev ( 2017-05-25 03:35:21 -0600 )edit

Yes, I know that openCV supports only evaluation. But, how do I save the model without the LogSoftMax function? After training the model from torch, I get a model.net file, which I want to import in openCV. So, how do I modify this binary file?

anomaly_ gravatar imageanomaly_ ( 2017-05-25 07:34:14 -0600 )edit

If you have Torch, you can load model. Try net = torch.load('model.net'). Then apply changes and save again.

dkurtaev gravatar imagedkurtaev ( 2017-05-25 08:37:43 -0600 )edit

It worked! Thanks a lot! :)

anomaly_ gravatar imageanomaly_ ( 2017-05-26 03:22:54 -0600 )edit

I am stuck with another issue. I was following the dnn tutorial for caffe, and I found a line net.setBlob(".data", inputBlob) to set the input blob. But in torch, since there is no prototxt file, how do I set the input blob? I did net.setBlob("l1_Convolution", inputBlob);where "l1_Convolution" is the name of my first layer. But this throws an error that I have described here http://answers.opencv.org/question/15...

anomaly_ gravatar imageanomaly_ ( 2017-05-26 07:18:08 -0600 )edit

You'd better follow sample with importing model from torch. Use net.setBlob("", inputBlob);. According to https://github.com/opencv/opencv_cont....

dkurtaev gravatar imagedkurtaev ( 2017-05-26 13:46:31 -0600 )edit

Hey, sorry if I am becoming a pain, but I really need to make through this. Any help will be highly appreciated. I did as described in the torch tutorial, but in net.forward() , I get this error : OpenCV Error: Assertion failed ((size_t)innerSize == innerSize0) in allocate, file /home/anomaly_/opencv-base/opencv_contrib/modules/dnn/src/layers/fully_connected_layer.cpp, line 89

anomaly_ gravatar imageanomaly_ ( 2017-05-27 01:59:29 -0600 )edit

Probably you put input blob with incorrect size. What architecture do you use? What image size you have been trying to process?

dkurtaev gravatar imagedkurtaev ( 2017-05-27 05:33:41 -0600 )edit

This is a link to my model.lua file https://gist.github.com/nitinkgp23/1a... It is a 2 class classification problem. I am inputting a 256x256 size image. How do I know whether I put the input blob with incorrect size? Please tell me if I need to provide any other info. I really have to get this done :(

anomaly_ gravatar imageanomaly_ ( 2017-05-27 16:10:29 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2017-05-17 11:09:57 -0600

Seen: 800 times

Last updated: May 17 '17