{"QuestionId":41241125,"AnswerCount":1,"Tags":"","CreationDate":"2016-12-20T11:19:30.813","AcceptedAnswerId":41245295.0,"OwnerUserId":3723434.0,"Title":"Siamese Net BackProp, how to effectively update?","Body":"

How to most effectively update the shared weights of a Siamese Net, given contrastive loss function in Tensorflow?<\/p>\n","answers":[{"AnswerId":"41245295","CreationDate":"2016-12-20T15:01:10.093","ParentId":null,"OwnerUserId":"2008194","Title":null,"Body":"

Abstract the network that produces the embeddings into a function. Just call the function twice - once for each image you pass in. It's referred to as two networks... that seems like an overstatement to me. It's just that you pass it through the same network. You'll want to reuse variables<\/a> in between the two function calls. My code looks something like this:<\/p>\n\n

def pipeline(images, reuse):\n  with tf.variable_scope('pipeline', reuse=reuse) as scope:\n  # ... conv layers etc. That produce the embedding.\n\noutput_a = pipeline(a_images, False)\noutput_b = pipeline(b_images, True)\n<\/code><\/pre>\n"}]}
{"QuestionId":41241491,"AnswerCount":2,"Tags":"","CreationDate":"2016-12-20T11:39:41.197","AcceptedAnswerId":null,"OwnerUserId":762517.0,"Title":"Sliding inner product using Tensorflow convolution","Body":"

I have two tensors of shape N x D1 and M x D2 where D1 > D2, called X and Y respectively. For my task, X acts as the input and Y acts as the filter.<\/p>\n\n

I want to calculate a matrix P of shape N x M x (D1-D2+1) such that:<\/p>\n\n

<\/pre>\n\n

I can create a for loop and manually slide Y and calculate the dot products. \nHowever I prefer using the correlation operator. \nAs I know, tensorflow has correlation operator implemented (https:\/\/www.tensorflow.org\/versions\/master\/api_docs\/python\/nn\/convolution<\/a>) but I don't know how can I use my tensors as inputs and filters. <\/p>\n","answers":[{"AnswerId":"46469931","CreationDate":"2017-09-28T13:04:54.060","ParentId":null,"OwnerUserId":"7704053","Title":null,"Body":"

Yes, you can use indeed tf.nn.conv2d(), but you should add both batch and channel dimensions:<\/p>\n\n

X = tf.expand_dims(tf.expand_dims(X,0),-1) \n# X.shape [batch=1, in_height, in_width, in_channels=1] \nY = tf.expand_dims(tf.expand_dims(Y,-1),-1)\n# Y.shape = [filter_height, filter_width, in_channels=1, out_channels=1]\n\n# Convolution (actually correlation, see doc of conv2d) \nxcorr = tf.nn.conv2d(X, Y, padding=\"VALID\", strides=[1, 1, 1, 1])\n# Padding should be VALID, since you've already padded your input\n<\/code><\/pre>\n\n

CAVEAT: However, you cannot extrapolate this approach for batches of signals, since tf.nn.conv2d uses always the same filter over the batch dimension, and from my understanding you do want to change it.<\/p>\n"},{"AnswerId":"41252408","CreationDate":"2016-12-20T22:44:53.950","ParentId":null,"OwnerUserId":"5549217","Title":null,"Body":"

tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, data_format=None, name=None)<\/p>\n\n

In your case, I'd set strides to 1, and padding to SAME.<\/p>\n\n

tf.nn.conv2d(X, Y, strides=1, padding=SAME)<\/p>\n"}]} {"QuestionId":41241523,"AnswerCount":0,"Tags":"","CreationDate":"2016-12-20T11:41:07.540","AcceptedAnswerId":null,"OwnerUserId":3610481.0,"Title":"caffe.set_mode_cpu() error in Caffe","Body":"

I have built caffe with only cpu support. Is the command 'caffe.set_mode_cpu() ' only used when we have built with gpu support so that we can switch to cpu when needed? I thought I might need it just to make sure that Caffe is using my cpu but I guess the build takes care of that. Also is this command required even when I have built with cpu support only?<\/p>\n\n

Error I get-<\/p>\n\n

<\/pre>\n\n

Problem posted on caffe users group<\/a><\/p>\n\n

This is my output of 'ccmake ..' . It says that CPU_ONLY is off even after removing the comment on CPU flag. How do I make it build with CPU for sure?\n\"Output<\/a><\/p>\n\n

To build Caffe, I used cmake .. instead of make as I got convert_imageset.bin error<\/a>. So I followed the instructions in the link and I got it to build properly.<\/p>\n\n

Now I was looking at my cmake output and realised that the \"CPU_ONLY\" option was set to off. So i followed this link<\/a> where i used \"cmake -DCPU_ONLY=ON\" to set it ON. <\/p>\n\n

But I'm still getting Cuda error even when cmake option \"CPU_ONLY=ON\" is there. I am not sure why it is still being built with GPU?<\/p>\n\n

Looking at my cmake output again, I found this error- <\/p>\n\n

<\/pre>\n\n

Is this fine since anyways we have to do make pycaffe to build with python?<\/p>\n","answers":[]} {"QuestionId":41243081,"AnswerCount":1,"Tags":"","CreationDate":"2016-12-20T13:05:11.353","AcceptedAnswerId":41252247.0,"OwnerUserId":4663495.0,"Title":"CNN model why the data is too large?","Body":"

\"the<\/p>\n\n

\"the<\/p>\n\n