在matlab function中导​入net,但是出现了​以下问题,尝试过6.​3和8.1版本的Mi​nG64,但是一直报​错。Deep learning code generation using MinGW64 Compiler (C++) toolchain is not supported for mkldnn target.

 Accepted Answer

MinGW is not supported for this workflow yet. Would you install the Visual Studio 2022 and use its compiler? See the webpage below for instruction
Next, in the command window, enter "mex -setup c++" command and select Visual Studio compiler for C++ Compilation, and see if the workflow works.
For more information, see the doc below.

11 Comments

谢谢你的回答,这个问题已经解决了。但是我又遇到了一个新的问题,我的net是在pyorch训练好了的,现在将.pt文件保存到matlab 中,通过importNetworkFromPyTorch导入到matlab,然后保存为net.mat.之后 使用net = coder.loadDeepLearningNetwork('net.mat');将其导入到matlab function。但是在运行过程中出现以下问题在层 'aten__linear0' 期间执行失败,请问呢这个是什么原因呢。
好的,谢谢。我还有一个问题。我发现我在pytorch中训练的模型通过net = importNetworkFromPyTorch(modelfile);导入到matlab后模型架构好像发生了变化。
I cannot figure out what's changed only by looking at the picture. Here is my suggestion: Please create a new question with ".pt" file and reproduction steps for your issue. Again, without reproducing your issue, it might be hard to understand your problem.
我上传了.pt文件,我想我没有清楚描述我的问题,我pytorch里面的网络从输入层linear[lay]出来并没有分支,而导入到matlab后aten_linea0出来就变成了2条支路,还有其它的支路都变成了两倍。
I see. I can understand your problem visually. However, @guiyang, can you use the paperclip icon to attach your .pt file? I want to reproduce your issue by myself. Also, I may have a chance to reach out to development team because it can be a bug. For that, I need your .pt file.
Also, please let me know the Python's dependency and MATLAB version (release name) for a better reproduction.
我上传了文件并压缩了。我的matlab版本是2024a,python为3.8。而且我发现了如果我直接用net = importNetworkFromPyTorch(modelfile) 这段代码生成net的话plot(net)的架构是错误的。但是我如果我在深度网络设计器app中从pytorch导入到app中,在从app中导出到工作区再plot(net)就是对的。因此这个问题我已经解决了。但是又有新的问题Unsupported custom layer 'aten__linear0'. Code generation does not support custom layers without '%#codegen' defined in the class definition.
Hi @guiyang, thank you so much for sharing the model. I will share it with dev team and report the issue. Also, it's great to know that you had some progress.
The new issue is about checking validity of custom layer. The issue is described in the docs below.
There must be multiple classes generated for the imported model like "aten_linear0.m". Would you add the %#codegen pragma for all the custom layer classes and see if you can fix the issue?
我加入了%#codegen,它显示了具体错误,错误如下Code generation for custom layer 'aten__linear0' for target 'mkldnn' is not supported as it returns a dlarray object with data format 'UU' as output 'out'.我尝试了各种方法但是并没有有效解决。
classdef aten__linear0 < nnet.layer.Layer & nnet.layer.Formattable & ...
nnet.layer.AutogeneratedFromPyTorch & nnet.layer.Acceleratable
%aten__linear0 Auto-generated custom layer
% Auto-generated by MATLAB on 2024-05-24 10:16:56
%#codegen
properties (Learnable)
% Networks (type dlnetwork)
end
properties
% Non-Trainable Parameters
end
properties (Learnable)
% Trainable Parameters
Param_weight
Param_bias
end
methods
function obj = aten__linear0(Name, Type, InputNames, OutputNames)
obj.Name = Name;
obj.Type = Type;
obj.NumInputs = 1;
obj.NumOutputs = 1;
obj.InputNames = InputNames;
obj.OutputNames = OutputNames;
end
function [linear_9] = predict(obj,linear_x_1)
%Validates that the input has the correct format and permutes its dimensions into the reverse of the original PyTorch format.
model_tt.ops.validateInput(linear_x_1,2);
[linear_x_1, linear_x_1_format] = model_tt.ops.permuteInputToReversePyTorch(linear_x_1, 2);
[linear_x_1] = struct('value', linear_x_1, 'rank', int64(2));
[linear_9] = tracedPyTorchFunction(obj,linear_x_1,false,"predict");
%Permute U-labelled output to forward PyTorch dimension ordering
if(any(dims(linear_9.value) == 'U'))
linear_9 = permute(linear_9.value, fliplr(1:max(2,linear_9.rank)));
end
end
function [linear_9] = forward(obj,linear_x_1)
%Validates that the input has the correct format and permutes its dimensions into the reverse of the original PyTorch format.
model_tt.ops.validateInput(linear_x_1,2);
[linear_x_1, linear_x_1_format] = model_tt.ops.permuteInputToReversePyTorch(linear_x_1, 2);
[linear_x_1] = struct('value', linear_x_1, 'rank', int64(2));
[linear_9] = tracedPyTorchFunction(obj,linear_x_1,true,"forward");
%Permute U-labelled output to forward PyTorch dimension ordering
if(any(dims(linear_9.value) == 'U'))
linear_9 = permute(linear_9.value, fliplr(1:max(2,linear_9.rank)));
end
end
function [linear_9] = tracedPyTorchFunction(obj,linear_x_1,isForward,predict)
linear_weight_1 = obj.Param_weight;
[linear_weight_1] = struct('value', dlarray(linear_weight_1,'UU'), 'rank', 2);
linear_bias_1 = obj.Param_bias;
[linear_bias_1] = struct('value', dlarray(linear_bias_1,'UU'), 'rank', 1);
[linear_9] = model_tt.ops.pyLinear(linear_x_1, linear_weight_1, linear_bias_1);
end
end
end

Sign in to comment.

More Answers (0)

Products

Release

R2023a

Asked:

on 20 May 2024

Commented:

on 20 Feb 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!