TensorFlow系列——环境相关
发布日期:2021-09-30 09:33:46
浏览次数:1
分类:技术文章
本文共 2566 字,大约阅读时间需要 8 分钟。
一、安装
1、win10系统pip方式安装
1.1、安装TensorFlow2.1.0
版本问题
使用python版本3.6
注意:TensorFlow2.3.0对应的python版本为3.7及3.8
- 遇到问题1:
最好不要用anaconda安装,有问题,就用pip方式安装。
- 遇到问题2:
importError: DLL load failed: 找不到指定的模块。解决方式:
1.2、安装TensorFlow2.4.0
使用python版本一定要用python3.7.x
不然会报错:windows fatal exception code 0xe06d7363
二、一些说明
1、版本问题
1.1、如何使用print打印出tensor的值的问题
在tensorflow2.x中默认开启了egar,所以给一个张量tensor可以直接print出张量tensor的值,例如:
import tensorflow as tfprint(tf.__version__)print(tf.executing_eagerly())x = [[2.]]m = tf.matmul(x, x)print("hello, {}".format(m))rank_0_tensor = tf.constant(4)print(rank_0_tensor)#输出:2.1.0Truehello, [[4.]]tf.Tensor(4, shape=(), dtype=int32)
而在tensorflow1.x中需要使用session方式才能打印tensor的值(run或者eval方法)
import tensorflow as tfprint(tf.executing_eagerly())x = [[2.]]m = tf.matmul(x, x)print("hello, {}".format(m))rank_0_tensor = tf.constant(4)print(rank_0_tensor)#输出:1.14.0Falsehello, Tensor("MatMul:0", shape=(1, 1), dtype=float32)Tensor("Const:0", shape=(), dtype=int32)
1.2、interleave读取tfrecordDataset
TensorFlow1.x中多线程读取dataset方式
tf.contrib.data.parallel_interleave(tf.data.TFRecordDataset,cycle_length=reader_num_threads)
TensorFlow2.x中修改为:
tf.data.Dataset.from_tensor_slices(train_files).interleave(map_func=lambda x:tf.data.TFRecordDataset(x),cycle_length=batch_size,block_length=1,num_parallel_calls=8)
1.3、本地打印print输出tfrecordDataset的值
# TensorFlow1.x中sess=tf.Session()element = dataset.make_one_shot_iterator()tmp = element.get_next()print(sess.run(tmp['fea_1']))# TensorFlow2.x中test_op = tf.compat.v1.data.make_one_shot_iterator(dataset)one_element = test_op.get_next()print(one_element['fea_1'])
1.4、自定义输入层(继承自keras.layers.Layer)处理shared_embedding特征的区别
# TensorFlow1.x# 注意:这里所用的feature_column都是来自于fc_v2,否则没有statemanagerimpl# shared_embedding_columns里面没有 statemanagerimpl,需要使用 shared_embedding_columns_v2from tensorflow.python.feature_column import feature_column_v2 as fc_v2self._state_magager = fc_v2._StateManagerImpl(self,trainable)transformation_catch = fc_v2.FeatureTransformationCache(inputs)act_first_fea4_emb,act_last_fea4_emb = fc_v2.shared_embedding_columns_v2([act_first_fea4,act_last_fea4],2,'mean',initializer=tf.initializers.glorot_normal,trainable=True)# TensorFlow2.x# 使用 shared_embeddingsfrom tensorflow.python.feature_column import feature_column_v2 as fc_v2self._state_magager = fc_v2._StateManagerImpl(self,trainable)transformation_catch = fc_v2.FeatureTransformationCache(inputs)act_first_fea2_emb,act_last_fea2_emb = tf.feature_column.shared_embeddings([act_first_fea2,act_last_fea2],5,'mean',initializer=tf.initializers.glorot_normal,trainable=True)
转载地址:https://blog.csdn.net/h_jlwg6688/article/details/116742174 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年04月25日 20时24分39秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
关于SAP的用户出口
2019-04-28
物料批次特性值
2019-04-28
sap中Excel的模版上传和下载
2019-04-28
SY-SUBRC 的含义
2019-04-28
定义物料管理的容差范围
2019-04-28
SAP中如何更改供应商账户组
2019-04-28
如何查询MySql日志
2019-04-28
ABAP SEARCH 搜索指定字符串
2019-04-28
条件 CHAIN 语句
2019-04-28
一般报java.lang.NullPointerException的原因有以下几种
2019-04-28
对于多个 BAPI一起commit!
2019-04-28
电商运营到底做什么?你所不知道的电商运营工作
2019-04-28
电子商务模式都有哪些
2019-04-28
Mule与Servicemix比较
2019-04-28
SAP 货物移动 BAPI 的简单使用 BAPI_GOODSMVT_CREATE
2019-04-28
Mule,目前综合状态最良好的开源ESB方案
2019-04-28
大洋洲群狼来了! 这是中国篮球学习契机?
2019-04-28
CTO到底应不应该写代码?听听硅谷大神们怎么说
2019-04-28
BW事务代码SXMB_ADM、 SICF、SMICM简介
2019-04-28
SAP配置webdynpro完全手册 .
2019-04-28