基於XILINX FPGA的卷積神經網路(三)

會思考的程式猿發表於2017-08-09

MATLAB程式碼


24x24圖片轉coe檔案


load('testset_image.mat')
a = image(1,:);
b = reshape(a,[24,24])';
c = reshape(b,[1,24*24]);


fid = fopen('image_24x24.coe','wt');
fprintf(fid,'memory_initialization_radix=10;\n');
fprintf(fid,'memory_initialization_vector=\n');
fprintf(fid,'%d,\n',c(1,:));
fclose(fid);


引數轉coe檔案


load('weight1.mat')
FIR_factor = a;
FIR_factor;
data_out = FIR_factor.*10000;
data_out = round(data_out);
data_out = [data_out(:,1,1,1);data_out(:,2,1,1);data_out(:,3,1,1);data_out(:,4,1,1);data_out(:,5,1,1);...
   data_out(:,1,1,2);data_out(:,2,1,2);data_out(:,3,1,2);data_out(:,4,1,2);data_out(:,5,1,2);...
   data_out(:,1,1,3);data_out(:,2,1,3);data_out(:,3,1,3);data_out(:,4,1,3);data_out(:,5,1,3);]




for ii = 1:length(data_out)
    if data_out(ii) < 0
        data_out(ii) = -data_out(ii) + 32768;
    end


end




fid = fopen('weight1_coe.coe','wt');
fprintf(fid,'memory_initialization_radix=16;\n');
fprintf(fid,'memory_initialization_vector=\n');
fprintf(fid,'%X,\n',data_out);
fclose(fid);

相關文章