dlarray Limitations for Code Generation - MATLAB & Simulink (original) (raw)

For code generation, use the dlarray (Deep Learning Toolbox) function to create deep learning arrays. For example, suppose you have a pretraineddlnetwork (Deep Learning Toolbox) network object in themynet.mat MAT-file. To predict the responses for this network, create an entry-point function in MATLAB® as shown in this code.

function a = foo(in) dlIn = dlarray(in, 'SSC');

persistent dlnet; if isempty(dlnet) dlnet = coder.loadDeepLearningNetwork('mynet.mat'); end

dlA = predict(dlnet, dlIn);

a = extractdata(dlA);

end

Using Variable-Size dlarray

You can generate code for MATLAB code that uses variable-size dlarray objects.

For example, define this MATLAB design file:

function out = fooAdd(in1,in2) %#codegen dlIn1_1 = dlarray(in1); dlIn1_2 = dlarray(in2); out = dlIn1_1 + dlIn1_2; end

Specify the two inputs in1 and in2 to be unbounded two-dimensional arrays of single type. Create the appropriate code configuration object cfg to generate generic C MEX code for fooAdd. Generate MEX code and run the generated MEX.

t_in1 = coder.typeof(single(1),[inf inf],[1 1]); t_in2 = coder.typeof(single(1),[inf inf],[1 1]);

codegen fooAdd -args {t_in1,t_in2} -report

out = fooAdd_mex(single(eye(4,4)),single(ones(4,1)));

When generating code for variable-size dlarray objects, adhere to these restrictions:

Limitations

For deep learning arrays, code generation has the following limitations:

end
In MATLAB, dlA is4(C)-by-5(B).
dlA =
4(C) × 5(B) dlarray
0.8147 0.9058 0.1270 0.9134 0.6324
0.0975 0.2785 0.5469 0.9575 0.9649
0.1576 0.9706 0.9572 0.4854 0.8003
0.1419 0.4218 0.9157 0.7922 0.9595
For standalone code generation, dlA is5(B)-by-4(C).

See Also

Objects

More About