【发布时间】:2020-12-10 14:27:16
【问题描述】:
我有 tuple numpy(len 4、5、6 或更多),如何将 tuple numpy 转换为 tuple tensor,输入如下:
import tensorflow as tf
import numpy as np
a = np.array([[20, 20], [40, 40]], dtype=np.int32)
b = np.array([[20, 20, 20], [40, 40, 40], [60, 60, 60]], dtype=np.int32)
c = np.array([[20, 20], [40, 40]], dtype=np.int32)
d = np.array([[20, 20, 20], [40, 40, 40], [60, 60, 60]], dtype=np.int32)
e = (a, b, c, d) # e is numpy tensor i want convert to tensor
tf_shapes = ((None, 2), (None, 3), (2, 2), (3, 3))
tf_types = (tf.int64, tf.float32, tf.int64, tf.float32)
我必须编写一个生成器将其转换为元组张量
def data_generator():
for i in range(16):
yield a, b, c, d
dataset=tf.data.Dataset.from_generator(data_generator, tf_types, tf_shapes).batch(batch_size=4, drop_remainder=True)
for sample in dataset:
res = model(sample, training=False)
如何不使用 tfdata 生成器直接获取样本。
【问题讨论】:
标签: numpy tensorflow tensorflow-datasets