[theano-users] Complex if/else operations in a custom loss function on 3-dimensional tensors
I am currently implementing the fully convolutional regression network which is outlined in detail in the paper "Synthetic Data for Text Localisation in Natural Images" by Ankush Gupta et al. I've got the network model compiled using the Keras API and I'm trying to implement the custom loss layer. This network outputs a tensor which is 7x16x16 and each of the 7 output values for the 16x16 output feature maps represents a different regressed value that ultimately helps to predict the possibility, size, and location of text in each convolutional cell. The part that's confusing me is implementing the special operations that need to be performed in the loss function. One of the 7 regressed output values, let's call it "c", represents the probability of a cell to contain text. This is used to help determine whether or not the loss of the other 6 output values even get back propagated. The rules in the custom loss function are as follows: 1. If the value 'c' is 0 (meaning there is no text in the current cell), the loss of the other 6 values is ignored completely (I'm assuming this means it's set to 0 and nothing is actually back-propagated, right?) and the MSE of the 'c' value is back-propagated. 2. If the value 'c' is 0, the MSE loss of the 'c' value is discounted. At the beginning of training, only 1% of the loss is back-propagated and this value is steadily increased throughout training until 100% of the loss is back propagated. So, since my output tensor is 7x16x16, I believe this means I have 7 different 16x16 matrices (feature maps) by which to specify the loss. I have an easier time thinking about a tensor that's 16x16x7 (which means each cell in the 16x16 matrix has 7 values) and I'm not exactly sure how to approach coding up the 2 rules that I specified because it looks like I need to specify them as lazily evaluated theano tensor functions instead of being able to loop through the tensors myself to apply the if/then/else logic. It would be helpful to be pointed in the right direction. I've looked at the documentation for the theano tensor functions already and I don't think I'm understanding exactly what a sequence of those functions may look like to help solve my problem. I can see there being an IfElse function in there but I'm not exactly sure how I would do the logic for the two steps I outlined above using this method. Thank you in advance for any examples, suggestions, or insight you are able to provide. -- --- You received this message because you are subscribed to the Google Groups "theano-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[theano-users] Apply generic element wise function against tensor
I have a tensor which is (7,16,16), let's denote as Tijk. I need to make the following function: for j in range(0, 16): for k in range(0, 16): if T0jk == 0: for i in range(1, 7): Tijk = 0 Any ideas on how this can be done with Theano's tensor API? Thanks! : -- --- You received this message because you are subscribed to the Google Groups "theano-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[theano-users] Re: Apply generic element wise function against tensor
Here's what my code in numpy looks like: tensor = shared(np.random.randn(7, 16, 16)) e_tensor = tensor.eval() tensor2 = e_tensor[0,:,:] tensor2[tensor2 < 1] = 0.0 tensor2[tensor2 > 0 = 1.0 new_tensor = [tensor2] for i in range(1, e_tensor.shape[0]): new_tensor.append(np.multiply(tensor2, e_tensor[i,:,:])) output = np.array(new_tensor).reshape(7,16,16) On Tuesday, January 17, 2017 at 10:47:24 AM UTC-5, Corey Nolet wrote: > > I have a tensor which is (7,16,16), let's denote as Tijk. I need to make > the following function: > > for j in range(0, 16): > for k in range(0, 16): > if T0jk == 0: > for i in range(1, 7): > Tijk = 0 > > > Any ideas on how this can be done with Theano's tensor API? > > > Thanks! : > > -- --- You received this message because you are subscribed to the Google Groups "theano-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to theano-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.