Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InvalidArgumentError: Expected dimension in the range [-1, 1) but got 1

I'm not sure what this error means. This error occurs when I try to calculate acc:

acc = accuracy.eval(feed_dict = {x: batch_images, y: batch_labels, keep_prob: 1.0})

I've tried looking up solutions, but I couldn't find any online. Any ideas on what's causing my error?

Here's a link to my full code.

like image 541
mdlee6 Avatar asked Jun 24 '17 21:06

mdlee6


Video Answer


3 Answers

For the people coming for Tensorflow serving or Estimator loading, this error occurs because the values in the feature dictionary need to be in batches.

data = {
        "signature_name": "predict",
        "inputs": {k:[v] for k,v in inputs.items()}
    }
like image 114
Daniyal Shahrokhian Avatar answered Sep 29 '22 23:09

Daniyal Shahrokhian


The source code generating this error reads as follows:

OP_REQUIRES(context, axis >= 0 && axis < input_dims,
            errors::InvalidArgument("Expected dimension in the range [",
                                    -input_dims, ", ", input_dims,
                                    "), but got ", dim));

Note that axis is required to be less than input_dims, not less-than-or-equal.

This conforms with the syntax [-1,1) in the message: [ indicates an inclusive value (such that -1 is valid), whereas ) indicates an exclusive value (putting 1 itself outside the range).

like image 44
Charles Duffy Avatar answered Sep 29 '22 23:09

Charles Duffy


I had a similar error but the problem for me was that I was trying to use argmax on a 1 dimensional vector. So the shape of my label was (50,) and I was trying to do a tf.argmax(y,1) on that when evaluating. The solution reference is Tensorflow: I get something wrong in accuracy

like image 43
Roshini Avatar answered Sep 30 '22 01:09

Roshini