How to perform bicubic interpolation on 'dlarray' objects and improve speed of user-defined implementation?

4 Ansichten (letzte 30 Tage)
I want to perform bicubic interpolation on 'dlarray' type objects. I am using functions like 'dlconv' and 'batchnorm' that return/accept 'dlarray' objects, so I have to do the resizing on 'dlarray'. I am using the 'dlresize' function for resizing. I found the lack of a 'bicubic' option in 'dlresize' (only 'nearest' and 'linear' methods can be selected). Therefore, I created my own implementation of bicubic interpolation to use with 'dlarray' objects.
However, the speed is really slow. What can I do to improve the speed of my implementation of bicubic interpolation for 'dlarray'?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 15 Sep. 2023
Bearbeitet: MathWorks Support Team am 15 Sep. 2023
Here are some suggested workarounds:
1. You could use the 'imresize' function instead of 'dlresize'. 'imresize' has an option to use bicubic interpolation. You can extract data from your 'dlarray' object using the 'extractdata' function and then pass it to 'imresize'. Following is a small example on how to do this:
X = rand(4,3);
dlX = dlarray(X)
Xtract = extractdata(dlX)
Xb = imresize(Xtract,2, 'bicubic') 
Note that  if you already have access to the data that you use to create your 'dlarray' object, you might not need to use 'extractdata'. Instead, you could directly pass that data as input to 'imresize'.
2. When the 'dlarray' is initialized through functions like 'dlconv', it gets some data format properties. You might lose these when using 'extractdata', which might cause errors (such as 'When the input data is an unformatted dlarray or numeric array, you must also specify the 'DataFormat' option') when using functions like 'batchnorm' later on in the code. So, you might have to explicitly ensure that these data format properties are being preserved. You can do this by copying the data format using the 'cast' function:
dlY_new = cast(dlY_new,"like",dlY_old)
Some functions, like 'batchnorm', also let you specify the data format in Name-Value pairs.
3. If 'imresize' does not work, locate the exact parts in your code that lead to slow performance. Here are some options that you can use to find where the code is slower -
4. There are also some standard tricks that you could use to make MATLAB code run faster. Following is a documentation link that goes through these techniques in detail:

Weitere Antworten (0)

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by