python - 在张量流数据集中将数据类型从 float32 更改为 float64
问题描述
我正在尝试将 pos_ds 数值特征的数据类型从 float32 更改为 float 64,但无法找到正确的方法。有什么建议么。我正在使用张量流 2.2。
def make_ds(features, labels):
ds = tf.data.Dataset.from_tensor_slices((dict(features), labels))#.cache()
ds = ds.shuffle(BUFFER_SIZE).repeat()
return ds
neg_ds = make_ds(neg_features, neg_labels)
pos_ds = make_ds(pos_features, pos_labels)
for features, label in pos_ds.take(1):
print("Features:\n", features.values())
print()
print("Label: ", label.numpy())
输出:
Features:
dict_values([<tf.Tensor: shape=(), dtype=float32, numpy=4.89784>, <tf.Tensor: shape=(), dtype=float32, numpy=4.727388>, <tf.Tensor: shape=(), dtype=float32, numpy=4.6051702>, <tf.Tensor: shape=(), dtype=float32, numpy=4.727388>, <tf.Tensor: shape=(), dtype=float32, numpy=4.804021>, <tf.Tensor: shape=(), dtype=float32, numpy=4.882802>, <tf.Tensor: shape=(), dtype=float32, numpy=4.912655>, <tf.Tensor: shape=(), dtype=string, numpy=b'nan'>, <tf.Tensor: shape=(), dtype=string, numpy=b'nan'>, <tf.Tensor: shape=(), dtype=string, numpy=b'nan'>, <tf.Tensor: shape=(), dtype=string, numpy=b'0.0'>, <tf.Tensor: shape=(), dtype=string, numpy=b'nan'>, <tf.Tensor: shape=(), dtype=string, numpy=b'NO_DCLRD_URL'>, <tf.Tensor: shape=(), dtype=string, numpy=b'nan'>])
Label: 1
解决方案
您可以在调用之前先将特征和 pos_labels 转换为张量from_tensor_slices
:
features = np.zeros(2, dtype=np.float32)
features = tf.convert_to_tensor(features,dtype=tf.float64)
ds = tf.data.Dataset.from_tensor_slices([features])
推荐阅读
- subquery - 带有偏移量 LIMIT 的慢 AQL 子查询
- angular - Angular Ngx-Bootstrap v.5.5.0 日期选择器
- android - 在项目-Android 中找不到 react-native-vector-icons/AntDesign
- python - 为什么全局变量不能在函数内部使用?
- java - Java 应用程序中的线程泄漏 - 导致 java.lang.OutOfMemoryError:无法创建新的本机线程
- java - Exception in thread "main" java.lang.RuntimeException: org.postgresql.util.PSQLException: FATAL: sorry, too many clients already
- oracle - TOAD Automation Designer Export to Excel utilizing Variables
- asp.net-mvc - How do I allow/deny users based on their Identity in a simple MVC application?
- c# - 需要帮助理解 MVVM 模型 WPF DataGrid
- java - I want to edit my recyclerview data on edit text changes and update in model which I am getting from service in json format