Why does TensorFlow convert my decoded image to float32 instead of uint8/16? The 2019 Stack Overflow Developer Survey Results Are InDoes Tensorflow uses vectorization in its operatorsTensorflow: can not convert float into a tensor?Why choose TensorFlow?Why Tensorflow does NOT quit when CUDA_ERROR_OUT_OF_MEMORYWhy is this TensorFlow CNN not generalising?How to convert my tensorflow model to pytorch model?How to properly rotate image and labels for semantic segmentation data augmentation in Tensorflow?does tensorflow use opencv to covert image to numpy arrayCrop all written letters from image to form a websiteTensorflow/Keras, How to convert tf.feature_column into input tensors?
Hello, Goodbye, Adios, Aloha
Mortgage adviser recommends a longer term than necessary combined with overpayments
Does Parliament need to approve the new Brexit delay to 31 October 2019?
Is every episode of "Where are my Pants?" identical?
How to substitute curly brackets with round brackets in a grid of list
Merge multiple DataFrames Pandas
Why are Marketing Cloud timestamps not stored in the same timezone as Sales Cloud?
What aspect of planet earth must be changed to prevent the industrial revolution?
Why can't wing-mounted spoilers be used to steepen approaches?
can infinity be divided by anything?
For what reasons would an animal species NOT cross a *horizontal* land bridge?
Is there a way to generate uniformly distributed points on a sphere from a fixed amount of random real numbers per point?
Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?
What can I do if neighbor is blocking my solar panels intentionally?
Variable with quotation marks "$()"
Ubuntu Err :18 http://dl.google.com/linux/chrome/deb stable Release.gpg KEYEXPIRED 1555048520
ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?
Variety of transposing instruments
Can we generate random numbers using irrational numbers like π and e?
Didn't get enough time to take a Coding Test - what to do now?
Why can't devices on different VLANs, but on the same subnet, communicate?
Using `min_active_rowversion` for global temporary tables
Can the DM override racial traits?
Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?
Why does TensorFlow convert my decoded image to float32 instead of uint8/16?
The 2019 Stack Overflow Developer Survey Results Are InDoes Tensorflow uses vectorization in its operatorsTensorflow: can not convert float into a tensor?Why choose TensorFlow?Why Tensorflow does NOT quit when CUDA_ERROR_OUT_OF_MEMORYWhy is this TensorFlow CNN not generalising?How to convert my tensorflow model to pytorch model?How to properly rotate image and labels for semantic segmentation data augmentation in Tensorflow?does tensorflow use opencv to covert image to numpy arrayCrop all written letters from image to form a websiteTensorflow/Keras, How to convert tf.feature_column into input tensors?
$begingroup$
I am using the following code to import a bunch of .png images and decode them using TensorFlow:
from __future__ import absolute_import, division, print_function
import tensorflow as tf
import numpy as np
import os
tf.enable_eager_execution()
NUM_TRAINING_SAMPLES = 333
NUM_CLASSES = 3
BATCH_SIZE = 5
NUM_EPOCHS = 6
INPUT_SIZE = (256, 256, 3)
random_indices = np.random.choice(range(13000), NUM_TRAINING_SAMPLES)
directory = "/home/local/CYCLOMEDIA001/ebos/Downloads/SYNTHIA_RAND_CVPR16"
directory_images = "/home/Downloads/SYNTHIA_RAND_CVPR16/RGB"
directory_labels = "/home/Downloads/SYNTHIA_RAND_CVPR16/GT"
train_images = np.array(os.listdir(directory_images))
train_labels = np.array(os.listdir(directory_images))
train_images = train_images[random_indices]
train_labels = train_labels[random_indices]
train_images = [tf.read_file(os.path.join(directory_images, img)) for img in train_images]
train_labels = [tf.read_file(os.path.join(directory_labels, img)) for img in train_labels]
train_images = [tf.io.decode_image(img, channels=3) for img in train_images]
train_labels = [tf.io.decode_image(img, channels=3) for img in train_labels]
train_images = tf.image.resize_images(train_images, INPUT_SIZE[:2])
train_labels = tf.image.resize_images(train_labels, INPUT_SIZE[:2])
train_dataset = tf.data.Dataset.from_tensor_slices((train_images, train_labels))
train_dataset = train_dataset.batch(3)
print(train_dataset.output_types)
This returns:
(tf.float32, tf.float32)
However, according to the documentation it should return a tensor of uint8's or uint16's. Why and where does the conversion take place?
I checked all intermediate steps with print statements, which doesn't tell me much as most intermediate lists are of class 'tensorflow.python.framework.ops.EagerTensor'.
python tensorflow cnn image-preprocessing
$endgroup$
add a comment |
$begingroup$
I am using the following code to import a bunch of .png images and decode them using TensorFlow:
from __future__ import absolute_import, division, print_function
import tensorflow as tf
import numpy as np
import os
tf.enable_eager_execution()
NUM_TRAINING_SAMPLES = 333
NUM_CLASSES = 3
BATCH_SIZE = 5
NUM_EPOCHS = 6
INPUT_SIZE = (256, 256, 3)
random_indices = np.random.choice(range(13000), NUM_TRAINING_SAMPLES)
directory = "/home/local/CYCLOMEDIA001/ebos/Downloads/SYNTHIA_RAND_CVPR16"
directory_images = "/home/Downloads/SYNTHIA_RAND_CVPR16/RGB"
directory_labels = "/home/Downloads/SYNTHIA_RAND_CVPR16/GT"
train_images = np.array(os.listdir(directory_images))
train_labels = np.array(os.listdir(directory_images))
train_images = train_images[random_indices]
train_labels = train_labels[random_indices]
train_images = [tf.read_file(os.path.join(directory_images, img)) for img in train_images]
train_labels = [tf.read_file(os.path.join(directory_labels, img)) for img in train_labels]
train_images = [tf.io.decode_image(img, channels=3) for img in train_images]
train_labels = [tf.io.decode_image(img, channels=3) for img in train_labels]
train_images = tf.image.resize_images(train_images, INPUT_SIZE[:2])
train_labels = tf.image.resize_images(train_labels, INPUT_SIZE[:2])
train_dataset = tf.data.Dataset.from_tensor_slices((train_images, train_labels))
train_dataset = train_dataset.batch(3)
print(train_dataset.output_types)
This returns:
(tf.float32, tf.float32)
However, according to the documentation it should return a tensor of uint8's or uint16's. Why and where does the conversion take place?
I checked all intermediate steps with print statements, which doesn't tell me much as most intermediate lists are of class 'tensorflow.python.framework.ops.EagerTensor'.
python tensorflow cnn image-preprocessing
$endgroup$
add a comment |
$begingroup$
I am using the following code to import a bunch of .png images and decode them using TensorFlow:
from __future__ import absolute_import, division, print_function
import tensorflow as tf
import numpy as np
import os
tf.enable_eager_execution()
NUM_TRAINING_SAMPLES = 333
NUM_CLASSES = 3
BATCH_SIZE = 5
NUM_EPOCHS = 6
INPUT_SIZE = (256, 256, 3)
random_indices = np.random.choice(range(13000), NUM_TRAINING_SAMPLES)
directory = "/home/local/CYCLOMEDIA001/ebos/Downloads/SYNTHIA_RAND_CVPR16"
directory_images = "/home/Downloads/SYNTHIA_RAND_CVPR16/RGB"
directory_labels = "/home/Downloads/SYNTHIA_RAND_CVPR16/GT"
train_images = np.array(os.listdir(directory_images))
train_labels = np.array(os.listdir(directory_images))
train_images = train_images[random_indices]
train_labels = train_labels[random_indices]
train_images = [tf.read_file(os.path.join(directory_images, img)) for img in train_images]
train_labels = [tf.read_file(os.path.join(directory_labels, img)) for img in train_labels]
train_images = [tf.io.decode_image(img, channels=3) for img in train_images]
train_labels = [tf.io.decode_image(img, channels=3) for img in train_labels]
train_images = tf.image.resize_images(train_images, INPUT_SIZE[:2])
train_labels = tf.image.resize_images(train_labels, INPUT_SIZE[:2])
train_dataset = tf.data.Dataset.from_tensor_slices((train_images, train_labels))
train_dataset = train_dataset.batch(3)
print(train_dataset.output_types)
This returns:
(tf.float32, tf.float32)
However, according to the documentation it should return a tensor of uint8's or uint16's. Why and where does the conversion take place?
I checked all intermediate steps with print statements, which doesn't tell me much as most intermediate lists are of class 'tensorflow.python.framework.ops.EagerTensor'.
python tensorflow cnn image-preprocessing
$endgroup$
I am using the following code to import a bunch of .png images and decode them using TensorFlow:
from __future__ import absolute_import, division, print_function
import tensorflow as tf
import numpy as np
import os
tf.enable_eager_execution()
NUM_TRAINING_SAMPLES = 333
NUM_CLASSES = 3
BATCH_SIZE = 5
NUM_EPOCHS = 6
INPUT_SIZE = (256, 256, 3)
random_indices = np.random.choice(range(13000), NUM_TRAINING_SAMPLES)
directory = "/home/local/CYCLOMEDIA001/ebos/Downloads/SYNTHIA_RAND_CVPR16"
directory_images = "/home/Downloads/SYNTHIA_RAND_CVPR16/RGB"
directory_labels = "/home/Downloads/SYNTHIA_RAND_CVPR16/GT"
train_images = np.array(os.listdir(directory_images))
train_labels = np.array(os.listdir(directory_images))
train_images = train_images[random_indices]
train_labels = train_labels[random_indices]
train_images = [tf.read_file(os.path.join(directory_images, img)) for img in train_images]
train_labels = [tf.read_file(os.path.join(directory_labels, img)) for img in train_labels]
train_images = [tf.io.decode_image(img, channels=3) for img in train_images]
train_labels = [tf.io.decode_image(img, channels=3) for img in train_labels]
train_images = tf.image.resize_images(train_images, INPUT_SIZE[:2])
train_labels = tf.image.resize_images(train_labels, INPUT_SIZE[:2])
train_dataset = tf.data.Dataset.from_tensor_slices((train_images, train_labels))
train_dataset = train_dataset.batch(3)
print(train_dataset.output_types)
This returns:
(tf.float32, tf.float32)
However, according to the documentation it should return a tensor of uint8's or uint16's. Why and where does the conversion take place?
I checked all intermediate steps with print statements, which doesn't tell me much as most intermediate lists are of class 'tensorflow.python.framework.ops.EagerTensor'.
python tensorflow cnn image-preprocessing
python tensorflow cnn image-preprocessing
asked Mar 30 at 15:46
EmielBossEmielBoss
185
185
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
Types are changing to float
due to tf.image.resize_images
.
Convert them back to uint
as follows:
train_images = tf.cast(train_images, dtype=tf.uint8)
train_labels = tf.cast(train_labels, dtype=tf.uint8)
Output:
(tf.uint8, tf.uint8)
Versions of my code:
tensorflow version: 1.14.1-dev20190330
numpy version: 1.16.2
$endgroup$
1
$begingroup$
Ah, that makes sense! I was also wondering why the floats actually had decimal values, but that must be because of the averaging, I assume. Thanks!
$endgroup$
– EmielBoss
Mar 30 at 16:37
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "557"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48262%2fwhy-does-tensorflow-convert-my-decoded-image-to-float32-instead-of-uint8-16%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Types are changing to float
due to tf.image.resize_images
.
Convert them back to uint
as follows:
train_images = tf.cast(train_images, dtype=tf.uint8)
train_labels = tf.cast(train_labels, dtype=tf.uint8)
Output:
(tf.uint8, tf.uint8)
Versions of my code:
tensorflow version: 1.14.1-dev20190330
numpy version: 1.16.2
$endgroup$
1
$begingroup$
Ah, that makes sense! I was also wondering why the floats actually had decimal values, but that must be because of the averaging, I assume. Thanks!
$endgroup$
– EmielBoss
Mar 30 at 16:37
add a comment |
$begingroup$
Types are changing to float
due to tf.image.resize_images
.
Convert them back to uint
as follows:
train_images = tf.cast(train_images, dtype=tf.uint8)
train_labels = tf.cast(train_labels, dtype=tf.uint8)
Output:
(tf.uint8, tf.uint8)
Versions of my code:
tensorflow version: 1.14.1-dev20190330
numpy version: 1.16.2
$endgroup$
1
$begingroup$
Ah, that makes sense! I was also wondering why the floats actually had decimal values, but that must be because of the averaging, I assume. Thanks!
$endgroup$
– EmielBoss
Mar 30 at 16:37
add a comment |
$begingroup$
Types are changing to float
due to tf.image.resize_images
.
Convert them back to uint
as follows:
train_images = tf.cast(train_images, dtype=tf.uint8)
train_labels = tf.cast(train_labels, dtype=tf.uint8)
Output:
(tf.uint8, tf.uint8)
Versions of my code:
tensorflow version: 1.14.1-dev20190330
numpy version: 1.16.2
$endgroup$
Types are changing to float
due to tf.image.resize_images
.
Convert them back to uint
as follows:
train_images = tf.cast(train_images, dtype=tf.uint8)
train_labels = tf.cast(train_labels, dtype=tf.uint8)
Output:
(tf.uint8, tf.uint8)
Versions of my code:
tensorflow version: 1.14.1-dev20190330
numpy version: 1.16.2
edited Mar 30 at 18:53
answered Mar 30 at 16:19
EsmailianEsmailian
3,156320
3,156320
1
$begingroup$
Ah, that makes sense! I was also wondering why the floats actually had decimal values, but that must be because of the averaging, I assume. Thanks!
$endgroup$
– EmielBoss
Mar 30 at 16:37
add a comment |
1
$begingroup$
Ah, that makes sense! I was also wondering why the floats actually had decimal values, but that must be because of the averaging, I assume. Thanks!
$endgroup$
– EmielBoss
Mar 30 at 16:37
1
1
$begingroup$
Ah, that makes sense! I was also wondering why the floats actually had decimal values, but that must be because of the averaging, I assume. Thanks!
$endgroup$
– EmielBoss
Mar 30 at 16:37
$begingroup$
Ah, that makes sense! I was also wondering why the floats actually had decimal values, but that must be because of the averaging, I assume. Thanks!
$endgroup$
– EmielBoss
Mar 30 at 16:37
add a comment |
Thanks for contributing an answer to Data Science Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48262%2fwhy-does-tensorflow-convert-my-decoded-image-to-float32-instead-of-uint8-16%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown