2 Star 0 Fork 0

Rocky / tensorflow-practise

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
eager_first.py 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
rockyzhengwu 提交于 2018-07-13 16:53 . add some
import tensorflow as tf
tf.enable_eager_execution()
print(tf.add(1, 2))
print(tf.add([1, 2], [3, 4]))
print(tf.square(5))
print(tf.reduce_sum([1, 2, 3]))
print(tf.encode_base64("hello world"))
# Operator overloading is also supported
print(tf.square(2) + tf.square(3))
x = tf.matmul([[1]], [[2, 3]])
print(x.shape)
print(x.dtype)
import numpy as np
ndarray = np.ones([3,3])
print("TensorFlow operations convert numpy arrays to Tensors automatically")
tensor = tf.multiply(ndarray, 42)
print(tensor)
print("And NumPy operations convert Tensors to numpy arrays automatically")
print(np.add(tensor, 1))
print("The .numpy() method explicitly converts a Tensor to a numpy array")
print(tensor.numpy())
ds_tensors = tf.data.Dataset.from_tensor_slices([1, 2, 3, 4, 5, 6])
import tempfile
_, filename = tempfile.mkstemp()
with open(filename, 'w') as f:
f.write("""Line 1
Line 2
Line 3
""")
ds_file = tf.data.TextLineDataset(filename)
print(ds_file)
ds_tensors = ds_tensors.map(tf.square).shuffle(2).batch(2)
ds_file = ds_file.batch(2)
print('Elements of ds_tensors:')
for x in ds_tensors:
print(x)
print('\nElements in ds_file:')
for x in ds_file:
print(x)
Python
1
https://gitee.com/rockyzheng/tensorflow-practise.git
git@gitee.com:rockyzheng/tensorflow-practise.git
rockyzheng
tensorflow-practise
tensorflow-practise
master

搜索帮助