{"QuestionId":43864956,"AnswerCount":0,"Tags":"","CreationDate":"2017-05-09T08:35:12.493","AcceptedAnswerId":null,"OwnerUserId":7827116.0,"Title":"ValueError: could not broadcast input array from shape (2,224,224,3) into shape (2,224,224)","Body":"

TensorFlow - How to predict with trained model on a different test dataset? I was working on Image segmentation. The prediction output have different dimension and give me hard time. Any help ..<\/p>\n\n

<\/pre>\n\n
\n\n

The error is on \"predict\"<\/strong> for \"train\"<\/strong> works perfectly. <\/p>\n\n

\"enter<\/a><\/p>\n","answers":[]} {"QuestionId":43865103,"AnswerCount":1,"Tags":"","CreationDate":"2017-05-09T08:42:59.817","AcceptedAnswerId":43899605.0,"OwnerUserId":null,"Title":"How to tackle overfitting with fully convolutional network in caffe","Body":"

I have a fully convolutional network (specifically the stacked hourglass network) in caffe. After each convolutional layer I have a batch normalisation and a scale layer and a ReLU layer. However, I encounter the problem of overfitting. Usually, I would increase my dataset (which is not possible) or I would use Dropout layers, but since I have read that it is not useful to use Dropout layers in fully convolutional networks I have no idea how to tackle the problem. Are there any things to do apart from what I have mentioned. Might Regulariztion be helpful in this case?<\/p>\n","answers":[{"AnswerId":"43899605","CreationDate":"2017-05-10T17:56:32.777","ParentId":null,"OwnerUserId":"4023951","Title":null,"Body":"

Here is a handy picture I stole from the interwebs. It is a handy chart of things to try when your deep learning model is having trouble. You say that you have heard that Dropout isn't good in Conv, but have you tested it? Start with that and proceed thusly :<\/p>\n\n

    \n
  1. Add dropout to Conv layer with a large depth dimension that is close to the output<\/li>\n
  2. Try not going deep<\/strong>. This is the reverse of go deep<\/em>, which you should try before going deep<\/em>. Make sure you have a simple model that doesn't overfit first<\/strong>, then try adding layers.<\/li>\n
  3. If you are still overfitting and you have dropout then try removing neurons<\/strong> by making your later Conv layers not have as much depth.<\/li>\n
  4. Do what Z.Kal says, multiply your dataset by transforming it.<\/li>\n
  5. And if all that doesn't make a difference accept the fact that your architecture is probably wrong. You have buried deep in it a way for it to store all the data you feed it verbatim without generalizing it. Consider making a squeeze point, where you have a layer that is small compared to the input data.<\/li>\n<\/ol>\n\n

    \"enter<\/a><\/p>\n"}]} {"QuestionId":43865115,"AnswerCount":1,"Tags":"","CreationDate":"2017-05-09T08:43:34.827","AcceptedAnswerId":43944318.0,"OwnerUserId":545089.0,"Title":"Why tf.nn.separable_conv2d uses with_space_to_batch?","Body":"

    The implementation of uses . But I don't see any difference in the outputs when is removed. What is the purpose of space to batch here? Is this a low-level optimization?<\/p>\n\n

    Related code;<\/p>\n\n

    <\/pre>\n","answers":[{"AnswerId":"43944318","CreationDate":"2017-05-12T18:26:02.577","ParentId":null,"OwnerUserId":"6392807","Title":null,"Body":"

    All the details you could ever want are in the comment describing with_space_to_batch<\/code>\nhttps:\/\/github.com\/tensorflow\/tensorflow\/blob\/master\/tensorflow\/python\/ops\/nn_ops.py#L149<\/a><\/p>\n\n

    Note in particular the following text:\n\"In the special case that dilation_rate<\/code> is uniformly 1, this simply returns: op(input, num_spatial_dims, padding)<\/code>\".<\/p>\n\n

    So space_to_batch<\/code> does nothing unless you have a dilated convolution.<\/p>\n"}]} {"QuestionId":43865736,"AnswerCount":1,"Tags":"","CreationDate":"2017-05-09T09:12:28.777","AcceptedAnswerId":null,"OwnerUserId":6573448.0,"Title":"Training image orientation classifier - Neural Network","Body":"

    I would like to train a conv neural network to detect the correct orientation of images. only 4 degrees (0,90,180 and 270).<\/p>\n\n

    The difficulty is that: the images will contain different objects - single person, group of person, mountain view, buildings, etc...<\/p>\n\n

    I was thinking of training the convNet on a big set of images. each image will be rotated 4 times (0,90,180 and 270). and each image will have a label (0 -> 0, 90 -> 1, 180 -> 2, 270 -> 3).<\/p>\n\n

    Are there other examples of orientation convNets \/ complex 4-class convNets \/ RNNs I could use for inspiration? (I'm using Caffe framework)<\/p>\n\n

    Thank you!<\/p>\n","answers":[{"AnswerId":"43868657","CreationDate":"2017-05-09T11:31:18.743","ParentId":null,"OwnerUserId":"1714410","Title":null,"Body":"

    A very interesting problem.
    \nI agree with your observation, that looking at specific objects in the photos and use their orientation to decide on the image orientation can be misleading. \nCheck this image for example:
    \n
    \"enter<\/a><\/p>\n\n

    It is perfectly oriented, yet the face is not upright. <\/p>\n\n

    Therefore, I suppose your approach to treat this problem as an image labeling problem (i.e., single orientation label per input image) is a good way to proceed.
    \nI would take any not-too-fancy off-the-shelf net and fine tune it based on the labeling you suggested.<\/p>\n\n

    Good luck!<\/p>\n"}]} {"QuestionId":43866265,"AnswerCount":0,"Tags":"","CreationDate":"2017-05-09T09:36:12.547","AcceptedAnswerId":null,"OwnerUserId":5887137.0,"Title":"Fail to install tensorflow from source in ubuntu","Body":"

    My story is:\nFirst, I install tensorflow by pip first, but it can not work in SSE4.2.\nThen I try to install it from source. My environment is:\n1) newly installed ubuntu.\n2) follow the instruction from tensorflow\n3) .\/Configure:<\/p>\n\n

    <\/pre>\n\n

    However, I got the following questions after importing tensorflow:<\/p>\n\n

    <\/pre>\n\n

    Could you help me point what is my mistake here? Many thanks!<\/p>\n","answers":[]} {"QuestionId":43866275,"AnswerCount":1,"Tags":"","CreationDate":"2017-05-09T09:36:48.700","AcceptedAnswerId":43944388.0,"OwnerUserId":7985305.0,"Title":"How does tf.sign work with back propagation?","Body":"

    I'm starting with TensorFlow, and I am trying to create a binary network. More specifically, I'm looking for a hashing network that would encode an image in a binary vector of size n. So I have a classic network, and I binarize the last layer before softmax.<\/p>\n\n

    TensorFlow provides a function that can do just that, but I can't figure out how the back-propagation can work in practice, since it's not continuous.<\/p>\n\n

    Any thoughts ?<\/p>\n","answers":[{"AnswerId":"43944388","CreationDate":"2017-05-12T18:30:53.123","ParentId":null,"OwnerUserId":"6392807","Title":null,"Body":"

    Unfortunately tf.sign()<\/code>'s gradient is always defined as 0<\/code> (probably because there is no good way to define it.)<\/p>\n\n

    https:\/\/github.com\/tensorflow\/tensorflow\/blob\/master\/tensorflow\/python\/ops\/math_grad.py#L542<\/a><\/p>\n\n

    @ops.RegisterGradient(\"Sign\")\ndef _SignGrad(op, _):\n  \"\"\"Returns 0.\"\"\"\n  x = op.inputs[0]\n  return array_ops.zeros(array_ops.shape(x), dtype=x.dtype)\n<\/code><\/pre>\n"}]}
    {"QuestionId":43866370,"AnswerCount":2,"Tags":"","CreationDate":"2017-05-09T09:41:09.713","AcceptedAnswerId":43871658.0,"OwnerUserId":1198173.0,"Title":"Tensorflow 'trainable=False' is ignored","Body":"

    I want to pass a fixed weight matrix to a 2D convolution operation in tensorflow. I tried putting as follows but TF seems to ignore the option.<\/p>\n\n

    <\/pre>\n\n

    It is constantly losing precision during training. The 1's become 0.98 then 0.96 etc and the 0's become 0.012 etc.<\/p>\n\n

    If I do the are not there. I can only find them in , so they are not even in the list of trainable variables. I can't figure out how to freeze the weights.<\/p>\n\n

    Possibly this line is at fault? \nhttps:\/\/github.com\/tensorflow\/tensorflow\/blob\/r1.1\/tensorflow\/python\/ops\/nn_ops.py#L1075<\/a><\/p>\n","answers":[{"AnswerId":"43871658","CreationDate":"2017-05-09T13:48:44.473","ParentId":null,"OwnerUserId":"1198173","Title":null,"Body":"

    Nevermind. My bad. In my code I was passing to minimize(var_list=tf.contrib.framework.get_variables())<\/code> instead of get_trainable_variables<\/code> which obviously overrides the trainable=False<\/code> argument.<\/p>\n"},{"AnswerId":"54226835","CreationDate":"2019-01-16T23:18:32.930","ParentId":null,"OwnerUserId":"5884955","Title":null,"Body":"

    Setting trainable=False<\/code> keeps the variable out of the GraphKeys.TRAINABLE_VARIABLES<\/code> collection in the graph, so they won't be trained when back-propagating.<\/p>\n\n

    It should work. No recent bugs.<\/p>\n"}]} {"QuestionId":43867032,"AnswerCount":3,"Tags":"","CreationDate":"2017-05-09T10:12:51.967","AcceptedAnswerId":null,"OwnerUserId":5606915.0,"Title":"How to fine-tune ResNet50 in Keras?","Body":"

    Im trying to finetune the existing models in Keras to classify my own dataset. Till now I have tried the following code (taken from Keras docs: https:\/\/keras.io\/applications\/<\/a>) in which Inception V3 is fine-tuned on a new set of classes.<\/p>\n\n

    <\/pre>\n\n

    Can anyone plz guide me what changes should I do in the above code so as to fine-tune ResNet50 model present in Keras.<\/p>\n\n

    Thanks in advance.<\/p>\n","answers":[{"AnswerId":"56435583","CreationDate":"2019-06-03T23:12:52.077","ParentId":null,"OwnerUserId":"11585252","Title":null,"Body":"

    I think I experienced the same issue. It appeared to be a complex problem, which has a decent thread on github(https:\/\/github.com\/keras-team\/keras\/issues\/9214<\/a>). The problem is in Batch Normalization of unfreezed blocks of the net. You have two solutions:<\/p>\n\n

      \n
    1. Only change top layer(leaving the blocks as they are)<\/li>\n
    2. Add a patch from the github thread above.<\/li>\n<\/ol>\n"},{"AnswerId":"43988194","CreationDate":"2017-05-15T20:23:41.217","ParentId":null,"OwnerUserId":"1908533","Title":null,"Body":"

      \nIt is difficult to make out a specific question<\/a>, have you tried anything more than just copying the code without any changes?<\/p>\n\n

      That said, there is an abundance of problems in the code<\/strong>: It is a simple copy\/paste from keras.io, not functional<\/strong> as it is, and needs some adaption before working at all (regardless of using ResNet50 or InceptionV3<\/strong>): <\/p>\n\n

      1): You need to define the input_shape when loading InceptionV3, specifically replace base_model = InceptionV3(weights='imagenet', include_top=False)<\/code> with base_model = InceptionV3(weights='imagenet', include_top=False, input_shape=(299,299,3))<\/code><\/p>\n\n

      2): Further, you need to adapt the number of the classes in the last added layer, e.g. if you have only 2 classes to: predictions = Dense(2, activation='softmax')(x)<\/code><\/p>\n\n

      3): Change the loss-function when compiling your model from categorical_crossentropy<\/code> to sparse_categorical_crossentropy<\/code><\/p>\n\n

      4): Most importantly, you need to define the fit_generator<\/code> before calling model.fit_generator()<\/code> and add steps_per_epoch<\/code>. If you have your training images in .\/data\/train<\/em> with every category in a different subfolder, this can be done e.g. like this:<\/p>\n\n

      from keras.preprocessing.image import ImageDataGenerator\ntrain_datagen = ImageDataGenerator()\ntrain_generator = train_datagen.flow_from_directory(\n     \".\/data\/train\",\n    target_size=(299, 299),\n    batch_size=50,\n    class_mode='binary')\nmodel.fit_generator(train_generator, steps_per_epoch=100)\n<\/code><\/pre>\n\n

      This of course only does basic training, you will for example need to define save calls to hold on to the trained weights. Only if you get the code working for InceptionV3 with the changes above I suggest to proceed to work on implementing this for ResNet50: As a start you can replace InceptionV3()<\/code> with ResNet50()<\/code> (of course only after from keras.applications.resnet50 import ResNet50<\/code>), and change the input_shape<\/code> to (224,224,3)<\/code> and target_size<\/code> to (224,244)<\/code>.<\/p>\n\n

      The above mentioned code-changes should work on Python 3.5.3 \/ Keras 2.0 \/ Tensorflow<\/em> backend.<\/p>\n"},{"AnswerId":"45470479","CreationDate":"2017-08-02T20:32:35.403","ParentId":null,"OwnerUserId":"6538094","Title":null,"Body":"

      Beyond the important points mentioned in the above answer for ResNet50 (! if your images are shaped into similar format as in the original Keras code (224,224) - not of rectangular shape) you may substitute:<\/p>\n\n

      # add a global spatial average pooling layer\nx = base_model.output\nx = GlobalAveragePooling2D()(x)\n<\/code><\/pre>\n\n

      by<\/p>\n\n

      x = base_model.output\nx = Flatten(x)\n<\/code><\/pre>\n\n

      EDIT: Please read @Yu-Yang comment bellow<\/p>\n"}]} {"QuestionId":43867435,"AnswerCount":0,"Tags":"","CreationDate":"2017-05-09T10:32:15.647","AcceptedAnswerId":null,"OwnerUserId":7984931.0,"Title":"How to constrain a layer to be a probability matrix?","Body":"

      I recently read this paper<\/a> which deals with noisy labels in convolutional neural networks.<\/p>\n\n

      They model label noise by a probability transition matrix which forms a simple \nconstrained linear layer after the softmax output.<\/p>\n\n

      So as an example we may have a 3-by-3 probability transition matrix (3 classes):<\/p>\n\n

      Example probability transition matrix. The sum of each column has to be 1.<\/a><\/p>\n\n

      This matrix Q is basically trained in the same way as the rest of the network via backpropagation. But it needs to be constrained to be a probability matrix. Quote from the paper: <\/p>\n\n

      \n

      After taking a gradient step with the Q and the model\n weights, we project Q back to the subspace of probability matrices because it represents conditional probabilities.<\/p>\n<\/blockquote>\n\n

      Now I am wondering what is the best way to implement such a layer in tensorflow.\nI have some ideas but i'm not sure what could work or is best procedure.<\/p>\n\n

      1) Hard code the constraint in the model before any training is done, something like:<\/p>\n\n

      <\/pre>\n\n

      2) Compute and apply gradients to the whole model (Q included), then apply constraint<\/p>\n\n

      <\/pre>\n\n

      I think the second approach is more related to the paper quote, but I am not sure to what extend external assignments confuse training. <\/p>\n\n

      Or maybe my ideas are bananas. I hope you can give me some advice!<\/p>\n","answers":[]} {"QuestionId":43868415,"AnswerCount":2,"Tags":"","CreationDate":"2017-05-09T11:19:30.090","AcceptedAnswerId":45724794.0,"OwnerUserId":5110359.0,"Title":"How to train a network in Keras for varying output size","Body":"

      I have basic neural network created with Keras. I train the network successfully with vectors of data and corresponding output data that is a vector with two elements. It represents a coordinate (x, y). So in goes an array, out comes an array. <\/p>\n\n

      Problem is that I am unable to use training data where a single input vector should correspond to many coordinates. Effectively, I desire a vector of coordinates as output, without prior knowledge of the number of coordinates.<\/p>\n\n

      Network is created by<\/p>\n\n

      <\/pre>\n\n

      and model summary shows the output dimensions for each layer <\/p>\n\n

      <\/pre>\n\n

      I realize the network structure only allows a length 2 vector as output. Dense layers also do not accept as their size. How do I modify the network so that it can train on and output a vector of vectors (list of coordinates)?<\/p>\n","answers":[{"AnswerId":"43870141","CreationDate":"2017-05-09T12:41:43.503","ParentId":null,"OwnerUserId":"349130","Title":null,"Body":"

      A recurrent neural networks (RNNs) would be much more appropriate, this models are typicall called seq2seq, that is, sequence to sequence. Recurrent nets use layers like LSTM and GRU, and can input and output variable length sequences. Just look at things like Machine Translation done with RNNs.<\/p>\n\n

      This can be done directly with keras, and there are many examples lying around the internet, for example this<\/a> one.<\/p>\n"},{"AnswerId":"45724794","CreationDate":"2017-08-17T00:17:31.950","ParentId":null,"OwnerUserId":"5000294","Title":null,"Body":"

      An rnn is not what you want for predicting coordinates. Instead, I would recommend using a model that predicts coordinates and associated confidences. So you would have 100 coordinate predictions for every forward pass through your model. Each of those predictions would have another associated prediction that determines if it is correct or not. Only predictions that are above a certain confidence threshold would count. That confidence threshold is what allows the model to choose how many points it wants to use each time (with a maximum number set by the number of outputs which in this example is 100). <\/p>\n\n

      r-cnn is a model that does just that. Here is the first keras implementaion I found on github https:\/\/github.com\/yhenon\/keras-frcnn<\/a>. <\/p>\n"}]} {"QuestionId":43868529,"AnswerCount":1,"Tags":"<3d>","CreationDate":"2017-05-09T11:25:19.123","AcceptedAnswerId":43918112.0,"OwnerUserId":7886997.0,"Title":"tensorflow neural network with 3d mesh as input","Body":"

      I\u2019m trying to build a neural network that takes as inputs the vertices position of a 3d mesh, \nand outputs the coordinates of two points on the inside. <\/p>\n\n

      for testing purpose I have a dataset containing a geometry with 20 points and two points on the inside for each one.<\/p>\n\n

      Every file of the dataset contains the coordinates of the vertices in a rank 2 with shape [3,20] array for the objs and shape [3,3] for the resulting points.<\/p>\n\n

      I\u2019ve built a linear model, but the outcome is always very low (0,16) , doesn\u2019t matter if I train it with 1000, 100.000 or 500.000<\/p>\n\n

      <\/pre>\n\n

      should I build a different kind of network?<\/p>\n\n

      Thanks\nE<\/p>\n","answers":[{"AnswerId":"43918112","CreationDate":"2017-05-11T14:21:24.933","ParentId":null,"OwnerUserId":"4023951","Title":null,"Body":"

      First, thanks for the clarification of the question in the comments, it really helps understand the problem.<\/p>\n\n

      The problem as I understand it is (at least similar to) : given a bounding set of 3D points of the outside of an arm, identify<\/p>\n\n