Problem: Image segmentation of forest area using CNN and MATLAB's BLOCKPROC function.
5 vues (au cours des 30 derniers jours)
Hello everyone, how are you?
I trained a Convolutional Neural Network - CNN (Resnet-18) to separate two classes (Palms / Non-Palms [background]) from a forest area.
Now, I need to generate the segmentation of the area from the trained network's result using the command:
C = semanticseg(I, network);
However, with the image being too large (21800x38480x3 uint8), the result shows the following error: "Maximum variable size allowed on the device is exceeded." Therefore, I decided to use a resource suggested by the Matlab website itself, which is to use the command BLOCKPROC, which processes the image in parts, which apparently would solve this problem of processing large images. So, I used the following commands:
I = imread('imagem.tif');
fun = @(block_struct) semanticseg(block_struct.data, network);
C = blockproc(I,[1000 1000],fun);
The result shows the following errors:
"Error using blockprocInMemory Invalid output class. The user function, FUN, returned an invalid result. The class of the result was categorical.
Error in blockproc (line 251) result_image = blockprocInMemory(source,fun,options);"
I didn't understand, as the result shouldn't be of the categorical class. I tried to modify the function to:
fun = @(block_struct) uint8(semanticseg(block_struct.data, net));
without success! :-(
Could someone please help me?
Information about my Computer:
Processor 12th Gen Intel(R) Core(TM) i7-12700H 2.30 GHz Installed RAM 32.0 GB (usable: 31.7 GB) System type 64-bit operating system, x64-based processor
Information about my Graphics Card:
CUDADevice with properties:
Name: 'NVIDIA GeForce RTX 3070 Ti Laptop GPU'
MaxShmemPerBlock: 49152 (49.15 KB)
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
TotalMemory: 8589410304 (8.59 GB)
AvailableMemory: 6583049776 (6.58 GB)
Joss Knight le 1 Mai 2023
In the documentation for semanticseg it says that the output is a categorical array.
Converting to uint8 would normally work, but not if the input image isn't uint8. To be sure try cast(...,'like',...), so:
proto = I(); % Reduce to simple prototype to avoid memory issues
fun = @(block_struct) cast(semanticseg(block_struct.data, net), 'like', proto);