You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.6 KiB
Matlab
57 lines
1.6 KiB
Matlab
function [H,W]=ism_dim(I,Locations,W)%,patches,patchLen)
|
|
numFeatureMaps=length(I);
|
|
numClasses=length(Locations);
|
|
[a,b]=size(I{1});
|
|
|
|
%define weights only for those inputs which are non-zero: weights will be
|
|
%specific to one particlular calculation (i.e. one specific image), but will
|
|
%require much less memory (assuming input is sparse) than defining weights for
|
|
%all inputs. Defining weights for all inputs can be done using the convolutional
|
|
%implementation of DIM so that we only need to store the convolution kernels,
|
|
%not many copies of the same weights, but this is much slower!
|
|
|
|
wmax=zeros(1,numClasses,'single');
|
|
for i=1:numFeatureMaps
|
|
for c=1:numClasses
|
|
wmax(c)=max(wmax(c),max(max(Locations{c}{i})));
|
|
end
|
|
end
|
|
|
|
Itotal=[];
|
|
k=0;
|
|
for i=1:numFeatureMaps
|
|
[x,y]=find(I{i}>0);
|
|
for j=1:length(x)
|
|
k=k+1;
|
|
%record non-zero values for input to neural network
|
|
Itotal(k,1)=I{i}(x(j),y(j));
|
|
|
|
%define Hough votes as weights fanning out from one input pixel
|
|
FmapTmp=zeros(a,b);
|
|
FmapTmp(x(j),y(j))=1;
|
|
|
|
wcolumn=[];
|
|
vcolumnScale=[];
|
|
for c=1:numClasses
|
|
wtmp=conv2(FmapTmp,Locations{c}{i},'same');
|
|
wcolumn=[wcolumn;wtmp(:)];
|
|
vcolumnScale=[vcolumnScale;ones(size(wtmp(:))).*wmax(c)];
|
|
end
|
|
W(:,k)=single(wcolumn);
|
|
end
|
|
end
|
|
[n,m]=size(W);
|
|
|
|
if isempty(Itotal)
|
|
H=zeros(a,b,numClasses);
|
|
else
|
|
%ignore neurons with zero weights to improve speed.
|
|
inc=find(sum(W,2)>0);
|
|
%apply PC/BC-DIM to process the inputs
|
|
yinc=dim_activation(W(inc,:),Itotal,bsxfun(@rdivide,W(inc,:),vcolumnScale(inc)));
|
|
%put zero activations for neurons with zero weights
|
|
y=zeros(n,1);
|
|
y(inc)=yinc;
|
|
H=reshape(y,a,b,numClasses);
|
|
end
|