tag:blogger.com,1999:blog-7583720.post4287464922088751151..comments2024-03-05T03:17:02.289-08:00Comments on Salmon Run: Migrating VGG-CNN from Caffe to KerasSujit Palhttp://www.blogger.com/profile/06835223352394332155noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-7583720.post-41031309083047700592020-04-29T10:23:44.709-07:002020-04-29T10:23:44.709-07:00That is weird, 428 is garden barrow according to t...That is weird, 428 is garden barrow according to the <a href="https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a" rel="nofollow">label list</a>. Not sure why this would be but perhaps others might be able to comment if they have seen something similar and what they needed to do to fix?Sujit Palhttps://www.blogger.com/profile/06835223352394332155noreply@blogger.comtag:blogger.com,1999:blog-7583720.post-76293382545877354272020-03-18T08:21:22.343-07:002020-03-18T08:21:22.343-07:00Thank you for your article. I have done everything...Thank you for your article. I have done everything as it is but the model is predicting incorrectly. It is giving label as 428 instead of 282Rehanhttps://www.blogger.com/profile/03119859602415567336noreply@blogger.comtag:blogger.com,1999:blog-7583720.post-56440528953007354462017-06-15T16:26:47.776-07:002017-06-15T16:26:47.776-07:00Thanks for the confirmation. I also tried running ...Thanks for the confirmation. I also tried running the code with just return W.T instead of W and that works also (it does the same as your np.transpose() call), also getting the same results as expected.<br />Sujit Palhttps://www.blogger.com/profile/06835223352394332155noreply@blogger.comtag:blogger.com,1999:blog-7583720.post-89401625902941646492017-06-15T15:54:01.042-07:002017-06-15T15:54:01.042-07:00Hi
I have found the solution.
This occurred becau...Hi<br />I have found the solution. <br />This occurred because of version incompatible in Keras 2v. <br />While Caffe weights are the in format of (depth, channels, rows , cols), Keras request format of (rows, cols, channels, depth). We can convert easily by 'np.transpose(W_conv1 , (2, 3, 1, 0)). kokul1984https://www.blogger.com/profile/12848521420109256216noreply@blogger.comtag:blogger.com,1999:blog-7583720.post-43694727608993416482017-06-15T11:06:04.295-07:002017-06-15T11:06:04.295-07:00You are right. I went back to my code on the Caffe...You are right. I went back to my code on the Caffe side, thinking that maybe I had flipped the dimensions here, but the documentation clearly tells me that the W_conv1 shape is (96, 3, 7, 7), while model.layers[0].get_weights() shows me that the expected shape in the network is (7, 7, 3, 96). If I remember correctly, I noticed this problem initially and then put it into my notes, but then it Sujit Palhttps://www.blogger.com/profile/06835223352394332155noreply@blogger.comtag:blogger.com,1999:blog-7583720.post-78180293238651528412017-06-15T02:39:48.848-07:002017-06-15T02:39:48.848-07:00Sujit, Thanks for your reply.
I have used your co...Sujit, Thanks for your reply.<br /><br />I have used your code without any modification.<br />I got the error " Layer weight shape (7, 7, 3, 96) not compatible with provided weight shape (96, 3, 7, 7)". <br />The reason is caffe's convolutional weight matrix dimension is different than Keras dimension. <br />I have found that function 'transform_conv_weight' doesn't kokul1984https://www.blogger.com/profile/12848521420109256216noreply@blogger.comtag:blogger.com,1999:blog-7583720.post-90320696887301548962017-06-14T17:30:20.596-07:002017-06-14T17:30:20.596-07:00Sorry, I think I definitely misled you with the de...Sorry, I think I definitely misled you with the description here... From what I see the data is stored correctly as (96, 3, 7, 7), and doesn't need to be changed to (7, 7, 3, 96). I will update the blog, sorry about that. However, you do need to rotate the data because of the difference in the way convolution works in Keras and Caffe. Also you need to transpose the FC weights.<br />Sujit Palhttps://www.blogger.com/profile/06835223352394332155noreply@blogger.comtag:blogger.com,1999:blog-7583720.post-3052147998401565612017-06-14T16:04:07.343-07:002017-06-14T16:04:07.343-07:00Hi Matt,
I am really interested about your post.
U...Hi Matt,<br />I am really interested about your post.<br />Unfortunately, I have faced a problem while using your code.<br />The "transform_conv_weight" function didn't change the weights from (96,3,7,7) to (7,7,3,96). I am using Keras 2.0.2 and caffe 1.0.<br />Shall I use np.transpose() to simply reverse the dimension of weights?kokul1984https://www.blogger.com/profile/12848521420109256216noreply@blogger.comtag:blogger.com,1999:blog-7583720.post-74717112972784280022017-02-03T08:15:29.637-08:002017-02-03T08:15:29.637-08:00These are good tips, thanks Matt.
These are good tips, thanks Matt.<br />Sujit Palhttps://www.blogger.com/profile/06835223352394332155noreply@blogger.comtag:blogger.com,1999:blog-7583720.post-76829374618392576312017-02-03T06:28:22.796-08:002017-02-03T06:28:22.796-08:00Hey Sujit --
Thank you!
This is awesome.
Jeremy...Hey Sujit --<br /><br />Thank you! <br />This is awesome. <br />Jeremy Howard describes 5 techniques to further improve the performance of a model in keras.<br />http://wiki.fast.ai/index.php/Lesson_3_Video_Timeline<br />He starts with low 90s (93% and gets to 99.7% with these techniques) over MNIST in the above<br /><br />High level Ideas<br /><br />1. data augmentation (you are already doing mattchttps://www.blogger.com/profile/02378228772557612664noreply@blogger.comtag:blogger.com,1999:blog-7583720.post-17113842765200341012017-01-31T10:42:48.134-08:002017-01-31T10:42:48.134-08:00Thanks Matt, glad you liked it. My objective here ...Thanks Matt, glad you liked it. My objective here was to replicate the VGG-CNN network (all of it) from Caffe to Keras. In Caffe, I was using it as a feature generator for my own images, by removing the PROB and FC7 layers - this transformed the input image into a vector of size (4096,), which I then used as input to different classification and similarity ranking pipelines. My intent for this Sujit Palhttps://www.blogger.com/profile/06835223352394332155noreply@blogger.comtag:blogger.com,1999:blog-7583720.post-76222253711325276052017-01-31T05:33:41.138-08:002017-01-31T05:33:41.138-08:00Sujit --- very informative writeup as always.
I ...Sujit --- very informative writeup as always. <br /><br />I wonder if adding to the keras code <br />.finetune(batches) <br />prior to softmax <br /><br />may make sense as it reduces the model to number of predicting classes your data cares about. <br /><br />This is Instead of the 1000 VGG layers vector. <br /><br />If you need the vector for similarity then finetune makes no sense.<br /><br />mattchttps://www.blogger.com/profile/02378228772557612664noreply@blogger.com