Retrieving Outputs From SPMD
3 次查看(过去 30 天)
显示 更早的评论
Here's the function I've been using without SPMD
function [mask] = bbox_analysis(bboxes, mask, blackwhiteframe, th, fractional_th)
% Cycle through every bbox in the frame
bbox_dim = size(bboxes);
for b = 1:bbox_dim(1)
x_1 = bboxes(b, 1);
y_1 = bboxes(b, 2);
x_2 = x_1 + bboxes(b, 3);
y_2 = y_1 + bboxes(b, 4);
cropped_image = imcrop(blackwhiteframe, [x_1, y_1, bboxes(b, 3), bboxes(b, 4)]); % Section of frame captured in bbox
max_image = max(cropped_image);
threshold = max(th/255, max_image*fractional_th);
new_image = (cropped_image > threshold);
for i = x_1:x_2-1
for j = y_1:y_2-1
mask(j, i) = new_image(j+1-y_1, i+1-x_1);
end
end
end
I've implemented SPMD in the following manner.
function [mask] = bbox_analysis(bboxes, mask, blackwhiteframe, th, fractional_th)
% Cycle through every bbox in the frame
spmd(0,6)
bbox_dim = size(bboxes);
for b = labindex:numlabs:bbox_dim(1)
x_1 = bboxes(b, 1);
y_1 = bboxes(b, 2);
x_2 = x_1 + bboxes(b, 3);
y_2 = y_1 + bboxes(b, 4);
cropped_image = imcrop(blackwhiteframe, [x_1, y_1, bboxes(b, 3), bboxes(b, 4)]); % Section of frame captured in bbox
max_image = max(cropped_image);
threshold = max(th/255, max_image*fractional_th);
new_image = (cropped_image > threshold);
for i = x_1:x_2-1
for j = y_1:y_2-1
mask(j, i) = new_image(j+1-y_1, i+1-x_1);
end
end
end
end
end
But now mask is returned as a composite variable and I would like to return in to the state it was originally being outputted. I've been having trouble understanding how to process the composite variable back into the original form it was being outputted in before I implemented SPMD. Does anyone know how I might be able to process the composite variable to cause it to return to the same form it existed in before? I would greatly appreciate any help in this regard.
0 个评论
采纳的回答
Sharmila Raghu
2017-4-3
In order to gather the individual components of the composite variable into a single array in the MATLAB base workspace, the following modifications must be done to the code:
1) The composite variable should be indexed starting from 1 on every lab. This is because every lab has its own local copy of the variable. Those labs do not know anything about where their work belongs in the whole array, so construct each individual array without taking indexing into account.
2) The final line of the SPMD block should be:
result = gcat(var,2,1);
Where var is the composite variable. This is a global concatenation of all OUTPUT variables, storing the result at lab index 1.
3) After the SPMD block, add the following code:
output = result{1};
This takes the globally concatenated values stored in 'result' and moves them into the base workspace in the variable 'output'.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!