question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Check failed: 1 == NumElements() (1 vs. 1792)Must have a one element tensor in Tensorflow C++

See original GitHub issue

Part of the code:

image_data = misc.imread(image_path)

image_batch = graph.get_tensor_by_name("input:0")
phase_train_placeholder = graph.get_tensor_by_name("phase_train:0")
embeddings = graph.get_tensor_by_name("embeddings:0")

feed_dict = {image_batch: np.expand_dims(image_data, 0), phase_train_placeholder: False}
rep = sess.run(embeddings, feed_dict=feed_dict)

C++ code: model: model-20170131-234652.ckpt-250000.pb

cv::Mat image = cv::imread("0002.png", CV_LOAD_IMAGE_COLOR);
const float * source_data = (float*) image.data;
Tensor image_batch(DT_FLOAT, TensorShape({1, 160, 160, 3}));
auto input = image_batch.tensor<float, 4>();
for (int y = 0; y < height; ++y) {
    const float* source_row = source_data + (y * width * depth);
    for (int x = 0; x < width; ++x) {
        const float* source_pixel = source_row + (x * depth);
        for (int c = 0; c < depth; ++c) {
            const float* source_value = source_pixel + c;
            //std::cout << *source_value << std::endl;
            input(0, y, x, c) = *source_value;
        }
    }
}
Tensor phase_train(DT_BOOL, TensorShape());
phase_train.scalar<bool>()() = false;

std::vector<std::pair<string, tensorflow::Tensor>> inputs = {
    { "input:0", image_batch },
    { "phase_train:0", phase_train },
};    
std::vector<Tensor> outputs;
Status run_status = session->Run(inputs, {"embeddings:0"}, {}, &outputs);

Error:

F tensorflow/core/framework/tensor.cc:493] Check failed: 1 == NumElements() (1 vs. 1792)Must have a one element tensor

Process finished with exit code 6

What is the reason for err?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
davidsandbergcommented, Mar 9, 2017

Hi @hipitt, It’s also important to do prewhitening of the image and also having the correct scaling of the face before cropping the image.

0reactions
anshan-arcommented, Aug 9, 2017

@hipitt , I use the code you published. However, the features extracted are not same with python code. Do you have same problem?

Read more comments on GitHub >

github_iconTop Results From Across the Web

1 == NumElements() (1 vs. 1792)Must have a one element ...
In the Python code, the image data is assigned to tensor image_batch: Part of the code:
Read more >
1 == NumElements() (1 vs. 1792)Must have a ... - appsloveworld
Coding example for the question Check failed: 1 == NumElements() (1 vs. 1792)Must have a one element tensor in Tensorflow C++-C++.
Read more >
Introduction to tensor slicing | TensorFlow Core
strided_slice to extract slices of tensors by 'striding' over the tensor dimensions. Use tf.gather to extract specific indices from a single axis of...
Read more >
Create an op | TensorFlow Core
It has an end-to-end code example, as well as Docker images for building and distributing your custom ops. If you'd like to create...
Read more >
Introduction to Tensors | TensorFlow Core
This will be an int32 tensor by default; see "dtypes" below. ... A "vector" or "rank-1" tensor is like a list of values....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found