I have designed a CNN with 2 convolution layers followed by 2 fully connected layers.
The architecture of my CNN is as follows:
Input -> [Conv1->ReLU->Pool] -> [Conv2->ReLU->Pool] -> FC1 -> FC2 -> output
28x28 28x28 14x14 14x14 7x7 49x1 49x1 10x1
While training the CNN, I have applied backpropagation till the Fully Connected layers. Without updating the filters I am getting the accuracy of around 94% but I need to update the filters for full functioning.
I am not able to figure out how do I propagate the error from FC layer to the filters in the conv layer.
I have referred to various sources but none of them helped me really. How do I propagate the error from a 49x49 FC layer to a 3x3 filter in conv layer?
Can anyone help me with this ?
Thank you.
The same way as you did for the fully connected layers but with convolution instead of matrix multiplications. Suppose you're at layer 5 (L5). During backprop you have a delta matrix that you have computed at L6, let's call it D6. In L5 you have 2tasks... You need to calculate dF that you will use to update filters, and you need to calculate D5 that you will use as the delta in L4.
How did you perform these in the dense layers? Well for dW you multiplied the layer input with the delta, while for the next delta you multiplied your delta with the weights and the derivative of the activation function.
Now comes the magic... If you have a conv layer make a wild guess what you do. Let me help a bit. To calculate dF you convolve D6 with the original input to L5. Looks familiar I hope. And to get the next delta you perform a full convolution of the original filters with D6, and pass that to L4. The pooling layers have a gazillion resources on them and they're pretty simple so I rather skip them.
If you're using python it's a good practice but don't expect it to be usable. It's awfully slow process, so for anything more than playing around use some framework like tensorflow/keras/etc.
Related
Let's say you're tracking a set of 20 segments with the same length belonging to the same 3D plane.
To visualize, imagine that you're drawing a set of segments of length 10 cm randomly on a sheet of paper. And make someone move this sheet in front of the camera.
Let's say those segments are represented by two points A and B.
Let's assume we manage to track A_t and B_t for all the segments. The tracked points aren't stable from frame to frame resulting in occasional jitter which might be solved by a Kalman filter.
My questions are concerning the state vector:
A Kalman filter for A and B for each segment (with 20 segments this results in 40 KF) is an obvious solution but it looks too heavy (knowing that this should run in real-time).
Since all the tracked points have the same properties (belonging to the same 3D plane, have the same length) isn't it possible to create one big KF with all those variables?
Thanks.
Runtime: keep in mind that the kalman equations involve matrix multiplications and one inversion. So having 40 states means having some 40x40 matrices. That will always take longer to calculate than running 40 one-state filters, where your matrices are 1x1 (scalar). Anyway, running the big filter only makes sense if you do know of a mathematical relationship between your states (=correlation), otherwise its output wise the same like running the 40 one-state filters.
With the information given thats really hard to tell. E.g. if your segments are always a polyline you could describe that differently in contrast to knowing nothing about the shape.
I am using the built-in radon function from the Image Processing Toolbox in MATLAB. Until today, I had been using some custom functions that gave me the results I expected. Particularly, I am developing a mathematical model that retrieves the projections of a Point Spread Function (PSF) in several directions (the baseline is 0/45/90/135 degrees).
I have prepared a really simple example that will show the problems I am experimenting:
I = zeros(1000,1000);
I(250:750, 250:750) = 1;
theta = [0 45 90 135];
[R,xp] = radon(I,theta);
figure;plot(R);legend('0°','45°','90°','135°');
If you run the example, you will see that the plot for 45/135° (diagonals) shows an artifact shaped as a saw-tooth along the curve. At first I thought it had to do with the sampling grid I am using (even number of points). However, when using a grid with an odd number of points, the problem remains there. I do not quite understand this result, since the radon transform is just a cumulative integral across several directions. Therefore, I should not get this "saw-tooth" pattern.
I am really confused about the result. Has anybody experimented the same problem?
Thanks in advance.
It is the aliasing artifact when you use a simple forward projector, which I believe is what implemented in the randon() function. To remove this artifact, you need to increase the number of samplings (randon() probably uses the same number of samplings of the phantom, you might want to increase that number to as least double the number of phantom samplings), or implement a better forward projector, such as driven-driven projector which is used in GE's CT image reconstruction software.
I'm working on a project in which a rod is attached at one end to a rotating shaft. So, as the shaft rotates from 0 to ~100 degrees back-and-forth (in the xy plane), so does the rod. I mounted a 3-axis accelerometer at the end of the moving rod, and I measured the distance of the accelerometer from the center of rotation (i.e., the length of the rod) to be about 38 cm. I have collected a lot of data, but I'm in need of help to find the best method to filter it. First, here's a plot of the raw data:
I think the data makes sense: if it's ramping up, then then I think at that point the acceleration should be linearly increasing, and then when it's ramping down, it should linearly decrease. If its moving constantly, the acceleration will be ~zero. Keep in mind though that sometimes the speed changes (is higher) from one "trial" to the other. In this case, there were ~120 "trials" or movements/sweeps, data sampled at 148 Hz.
For filtering, I've tried a low pass filter and then an exponentially decreasing moving average, and both plots weren't too hot. And although I'm not good at interpreting these: here is what I got when coding a power frequency plot:
What I was hoping to get help with here is, attain a really good method by which I can filter this data. The one thing that keeps coming up again time and time again (especially on this site) is the Kalman filter. While there's lots of code online that helps implementing these in MATLAB, I haven't been able to actually understand it that great, and therefore neglect to include my work on it here. So, is a kalman filter appropriate here, for rotational acceleration? If so, can someone help me implement one in matlab and interpret it? Is there something I'm not seeing that may be just as good/better that is relatively simple?
Here's the data I'm talking about. Looking at it more closely/zooming in gives a better appreciation for what's going on in the movement, I think:
http://cl.ly/433B1h3m1L0t?_ga=1.81885205.2093327149.1426657579
Edit: OK, here is the plot of both relavent dimensions collected from the accelerometer. I am neglecting to include the up and down dimension as the accelerometer shows a near constant ~1 G, so I think its safe to say its not capturing much rotational motion. Red is what I believe is the centripetal component, and blue is tangential. I have no idea how to combine them though, which is why I (maybe wrongfully?) ignored it in my post.
And here is the data for the other dimension:
http://cl.ly/1u133033182V?_ga=1.74069905.2093327149.1426657579
Forget the Kalman filter, see the note at the end of the answer for the reason why.
Using a simple moving average filter (like I showed you on an earlier reply if i recall) which is in essence a low-pass filter :
n = 30 ; %// length of the filter
kernel = ones(1,n)./n ;
ysm = filter( kernel , 1 , flipud(filter( kernel , 1 , flipud(y) )) ) ;
%// assuming your data "y" are in COLUMN (otherwise change 'flipud' to 'fliplr')
note: if you have access to the curvefit toolbox, you can simply use: ys = smooth(y,30) ; to get nearly the same result.
I get:
which once zoomed look like:
You can play with the parameter n to increase or decrease the smoothing.
The gray signal is your original signal. I strongly suspect that the noise spikes you are getting are just due to the vibrations of your rod. (depending on the ratio length/cross section of your rod, you can get significant vibrations at the end of your 38 cm rod. These vibrations will take the shape of oscillations around the main carrier signal, which definitely look like what I am seeing in your signal).
Note:
The Kalman filter is way overkill to do a simple filtering of noisy data. Kalman filter is used when you want to calculate a value (a position if I follow your example) based on some noisy measurement, but to refine the calculations, the Kalman filter will also use a prediction of the position based on the previous state (position) and the inertial data (how fast you were rotating for example). For that prediction you need a "model" of the behavior of your system, which you do not seem to have.
In your case, you would need to calculate the acceleration seen by the accelerometer based on the (known or theoretical) rotation speed of the shaft at any point of time, the distance of the accell to the center of rotation, and probably to make it more precise, a dynamic model of the main vibration modes of your rod. Then for each step, compare that to the actual measurement... seems a bit heavy for your case.
Look at the quick figure explaining the Kalman filter process in this wikipedia entry : Kalman filter, and read on if you want to understand it more.
I will propose for you low-pass filter, but ordinary first-order inertial model instead of Kalman. I designed filter with pass-band till 10 Hz (~~0,1 of your sample frequency). Discrete model has following equation:
y[k] = 0.9418*y[k-1] + 0.05824*u[k-1]
where u is your measured vector, and y is vector after filtering. This equation starts at sample number 1, so you can just assign 0 to the sample number 0.
I have applied dwt2 on 2D image, applied source and channel coding on LL sub band and transmitted it.
Now I have a question on the receiver side. Do I have to apply source and channel coding on HL, LH, HH and transmit as well to reconstruct the image on the other end (using idwt)? Is it possible to reconstruct LL sub band without the rest? I am asking this so as to save the computational time. What do you guys suggest?
The low passed part and high passed part of a wavelet decomposed signal are independent (actually orthogonal to each other), for a 2D image, you will have four sub-images after one level of decomposition and all of them are not related to each other.
So if the low frequency blurred image (LL part) is all you want to recover on the receiver side, you won't need the other parts.
Specifically I'd ideally want images with point correspondences and a 'Gold Standard' calculated value of F and left and right epipoles. I could work with an Essential matrix and intrinsic and extrinsic camera properties too.
I know that I can construct F from two projection matrices and then generate left and right projected point coordinates from 3D actual points and apply Gaussian noise but I'd really like to work with someone else's reference data since I'm trying to test the efficacy of my code and writing more code to test the first batch of (possibly bad) code doesn't seem smart.
Thanks for any help
Regards
Dave
You should work with ground truth datasets for multi-view reconstructions. I recommend to use the Middlebury Multi-View Stereo datasets. Besides the image data in lossless format, they deliver camera parameters, such as camera pose and intrinsic camera calibration as well as the possibility to evaluate your own multi-view reconstruction system.
Perhaps, the results are not computed by "the" gold standard algorithm proposed in the book of Hartley and Zisserman but you can use it to compute the fundamental matrices you require between two views.
To compute the fundamental matrix F from two projection matrices P1 and P2 refer to the code Andrew Zisserman provides.