create hfd5 with float numbers for caffe - neural-network

I want to feed caffe vectors of labels (multi label regression problem), so I have used the following link for creating hdf5 files.
Using this code, I created an image_list.txt which contains path of files and float labels in each line, e.g.
/home/deep/00000.bmp 0.9997 0.0236 -0.0082 -0.0231 0.9980 0.0588 0.0096 -0.0586 0.9982 -0.0046 0.1084 0.3938
but it seems that it only works for integer label.
when I run demo.m the following error comes:
Error using dataread
Trouble reading integer from file (row 1, field 3) ==> .9997 0.0236 -0.0082 -0.0231 0.9980
0.0588 0.

If you also use caffe's C++ interface, I would like to share you with this Multitask DataLayer and it supports float typed label vector for regression tasks. Here provides a simple example for learning facial expressions' label distribution which is a vector size of 8.

Related

Matlab function reshape doesnt´t calculate the last dimension while trying to create a 3D image from .raw binary image file

I created binarized images by using the Otsu methode in Matlab and cut out parts of the resulting image using a function. Now i want to take a look at these images with the VolumeViewer command. I know the x,y and z dimensions of the resulting imgages. I currently run this code doing it(excluding the volumeViewerwhich happens after the loop):
files= {'C3\C3_000mal_550_539_527.raw';...
};
for i=1:numel(files)
Image = fopen(files{i},'r');
ImageData{i} = fread(Image,Inf,'uint16=>uint16');
ImageData{i} = reshape(ImageData{i},550,539,[]);
fclose(openedCrystalImage);
end
Using this code runs into the following error using reshape:
Error using reshape
Product of known dimensions, 296450, not divisible into total number of elements, 78114575.
I did the maths and 550*539=296450 and 296450 * 527=156229150: If we divide the last number by the number of elements it equals 2 and thus is divisible into the total number of elements. In my opinion the reshape function is not able to find the size of the last dimension or defines it as 1.
Defining the size of z also results in an error suggesting using the brackets [], so the function can find it.
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size
for that dimension.
Now to the weird part. This code works for another set of images, with diffrent sizes of the x,y and z ranges. So don´t know where the issue lies to be frank. So i would really appreciate and Answer to my question
I figured it out. The error lies here:
ImageData{i} = fread(Image,Inf,'uint16=>uint16');
Apparently by saving them as .raw before it converts the image to an 8 bit file rather than 16 bits it had before. Therefore, my dimension is double the size of the number of elements. With this alteration it works:
ImageData{i} = fread(Image,Inf,'uint8=>uint8');
The reason i was able to look at the other pictures was that the z range was divisble by 2.
So the reshape function was not the problem but size of the integer data while creating the array for the variable ImageData.
P.S. I just started out programming so the accuracy in the answer should be taken with a grain of salt

MATLAB CSV Import Warping Data

When I import my data (numerical matrix of NYSE stock data), the data isn't loaded properly:
the final part of my CSV data disp() displayed should be -
9.76, 10, 9.99, 9.94, 9.97,9.944,9.95,10,9.956,10.01
What I get when I call the disp(importDataResult) is -
0.0100 0.0099 0.0099 0.0100 etc..
Have you got any idea why when I import the data it is transformed completely? The below link contains my zipped CSV file so you can see the problem (I completely understand if you can't be bothered checking this out, but I'd be interested to know if the same problem applies to others' MATLAB / computers).
https://www.sendspace.com/file/slif0y
The code I'm using is:
function [ c ] = CreateCov_Test()
c = csvread('nyse_data_matrix_no_tags.csv');
disp(c);
end
Here is a screenshot of the issue:
https://s32.postimg.org/os74qfrlx/matlab_screen.png
Thank you very much!
Matlab is not transforming any data. The configuration of who Matlab is displaying variables is controlled with format, the default being format short.
An excerpt from the documentation:
format may be used to switch between different output display formats of all float variables as follows:
format SHORT Scaled fixed point format with 5 digits.
So what does Scaled fixed point format with 5 digits mean, well lets see
>> a = [0.1 10000 100]
>> disp(a)
1.0e+04 *
0.0000 1.0000 0.1000
Note the 1.0e+04 *, its a multiplier for all data in the matrix. When displaying a large matrix, this multiplier is often hidden (as in your case), which admittedly can be rather confusing.

MATLAB NN toolbox: Error using trainlm

I have a 90×8 dataset that I feature-extracted (by summing 1's in every 10×10 cell) from 90 character images i.e. digits 1-9. Every row represents an image.
I am trying to use following code to train a neural network and recognize new input images(that are digits between 1 and 9 inclusive):
net.trainFcn='traingdx';
net.performFcn='sse';
net.trainParam.goal=0.1;
net.trainParam.show=20;
net.trainParam.epochs=5000;
net.trainParam.mc=0.95;
net =newff(minmax(datasetNormalized'),[20 9],{'logsig' 'logsig'});
T=reshape(repmat([1:9],10,1),1,90);
[net,tr]=train(net,datasetNormalized,T);
Afterwards I want to use the following to recognize new images using the trained network. m is an image character that has also been feature extracted.
[a,m]=max(sim(net,m));
disp(b);
I am getting the following errors and I don't have any idea how to solve it:
Error using trainlm (line 109)
Inputs and targets have different numbers of samples.
Error in network/train (line 106) [net,tr] =
feval(net.trainFcn,net,X,T,Xi,Ai,EW,net.trainParam);
Error in Neural (line 55) [net,tr]=train(net,datasetNormalized,T);
Note: datasetNormalized is my dataset normalized in [0,1].
Which part causes the problem?
Inputs and targets have different numbers of samples. it seems to be the problem
T=reshape(repmat([1:9],10,1),1,90) --> T=reshape(repmat([1:9],10,1),90,1)
[net,tr]=train(net,datasetNormalized,T); --> [net,tr]=train(net,datasetNormalized',T);
T is to be used as target for the network; Therefore, following a friend's advice, I defined T as a 9*90 array in such a way that the first 10 columns have 1 in their first row-other rows being zero, the second 10 columns have 1 in their second row, and so on
T=zeros(9,90);
for j=1:90
i=ceil(j/10);
T(i,j)=1;
end
[net,tr]=train(net,datasetNormalized',T);
This solved the error I was getting upon training network, though I'm not still sure how it's going to be mapped to input characters and determine them.

basic - Trying to add noise to an Audio file and trying to reduce errors using basic coding such as Repeatition code

We were recently taught the concepts of error control coding - basic codes such as Hamming code, repeatition code etc.
I thought of trying out these concepts in MATLAB. My goal was to compare how an audio file plays when corrupted by noise and in the case when the file is protected by basic codes and then corrupted by noise.
So I opened a small audio clip of 20-30 seconds in MATLAB using audioread function. I used 16 bit encoded PCM wave file.
If opened in 'native' format it is in int16 format . If not it opens in a double format.
I then added two types of noises to it : - AWGN noise (using double format) and Binary Symmetric Channel noise (by converting the int16 to uint16 and then by converting that to binary using dec2bin function). Reconverting back to the original int16 format does add a lot of noise to it.
Now my goal is to try out a basic repeatition code. So what I did was to convert the 2-d audio file matrix which consists of binary data into a 3-d matrix by adding redundancy. I used the following command : -
cat(3,x,x,x,x,x) ;
It created a 3-D matrix such that it had 5 versions of x along the 3rd dimension.
Now I wish to add noise to it using bsc function.
Then I wish to do the decoding of the redundant data by removing the repetition bits using a mode() function on the vector which contains the redundant bits.
My whole problem in this task is that MATLAB is taking too long to do the computation. I guess a 30 second file creates quite a big matrix so maybe its taking time. Moreover I suspect what I am doing is not the most efficient way to do it with regards to the various data types.
Can you suggest a way in which I may improve on the computation times. Are there some functions which can help do this basic task in a better way.
Thanks.
(first post on this site with respect to MATLAB so bear with me if the posting format is not upto the mark.)
Edit - posting the code here :-
[x,Fs] = audioread('sample.wav','native'); % native loads it in int16 format , Fs of sample is 44 khz , size of x is 1796365x1
x1 = x - min(x); % to make all values non negative
s = dec2bin(x); % this makes s as a 1796365x15 matrix the binary stream stored as character string of length 15. BSC channel needs double as the data type
s1 = double(s) - 48; % to get 0s and 1s in double format
%% Now I wish to compare how noise affects s1 itself or to a matrix which is error control coded.
s2 = bsc(s,0.15); % this adds errors with probability of 0.15
s3 = cat(3,s,s,s,s,s) ; % the goal here is to add repetition redundancy. I will try out other efficient codes such as Hamming Code later.
s4 = bsc(s3,0.15);% this step is taking forever and my PC is unresponsive because of this one.
s5 = mode(s4(,,:)) ; % i wish to know if this is a proper syntax, what I want to do is calculate mode along the 3rd dimension just to remove redundancy and thereby reduce error.
%% i will show what I did after s was corrupted by bsc errors in s2,
d = char(s2 + 48);
d1 = bin2dec(d) + min(x);
sound(d1,Fs); % this plays the noisy file. I wish to do the same with error control coded matrix but as I said in a previous step it is highly unresponsive.
I suppose what is mostly wrong with my task is that I took a large sampling rate and hence the vector was very big.

how to code a function in matlab which will display pixels of an gray image which is not repeated

hi i m trying to implement huffman code which has following steps:
Development of Huffman Coding and Decoding Algorithm
Step1- Read the image on to the workspace of the mat
lab.
Step2- Convert the given colour image into grey level
image.
Step3- Call a function which will find the symbols (i.e.
pixel value which is non-repeated).
Step4- Call a function which will calculate the
probability of each symbol.
Step5- Probability of symbols are arranged in decreasing
order and lower probabilities are merged and this
step is continued until only two probabilities are
left and codes are assigned according to rule that
:the highest probable symbol will have a shorter
length code.
Step6- Further Huffman encoding is performed i.e.
mapping of the code words to the corresponding
symbols will result in a compressed data.
Step7- The original image is reconstructed i.e.
decompression is done by using Huffman
decoding.
Step8- Generate a tree equivalent to the encoding tree.
Step9- Read input character wise and left to the table II
until last element is reached in the table II.
Step10 -Output the character encode in the leaf and return
to the root, and continue the step9 until all the
codes of corresponding symbols are known.
i have implemented steps 1 & 2..in 3rd steps i m able to display the pixels of an image using function impixelregion; but i m not able to find how to code a function which will display pixels values which are not repeated..kindly help me plzzz...
See imhist i.e. use imhist(I,256), where I is your gray image.