tf.io.read_file
Stay organized with collections
Save and categorize content based on your preferences.
Reads the contents of file.
tf.io.read_file(
filename, name=None
)
Used in the notebooks
Used in the guide |
Used in the tutorials |
|
|
This operation returns a tensor with the entire contents of the input
filename. It does not do any parsing, it just returns the contents as
they are. Usually, this is the first step in the input pipeline.
Example:
with open("/tmp/file.txt", "w") as f:
f.write("asdf")
4
tf.io.read_file("/tmp/file.txt")
<tf.Tensor: shape=(), dtype=string, numpy=b'asdf'>
Example of using the op in a function to read an image, decode it and reshape
the tensor containing the pixel data:
@tf.function
def load_image(filename):
raw = tf.io.read_file(filename)
image = tf.image.decode_png(raw, channels=3)
# the `print` executes during tracing.
print("Initial shape: ", image.shape)
image.set_shape([28, 28, 3])
print("Final shape: ", image.shape)
return image
Args |
filename
|
string. filename to read from.
|
name
|
string. Optional name for the op.
|
Returns |
A tensor of dtype "string", with the file contents.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[]]