
tensorflow
代码随想随记
211本硕,人工智能方向,前A应用算法专家,发明专利十余项,目前致力于大模型和RAG方向。
懂点工程,会点算法,
如有机器学习/深度学习/大模型/RAG等方向朋友可以一起探讨。
展开
-
module ‘tensorflow‘ has no attribute ‘Session‘或者‘InteractiveSession‘
改一行代码就行,将import tensorflow as tf改成import tensorflow.compat.v1 as tf就可以了。原创 2020-11-28 12:47:47 · 1978 阅读 · 0 评论 -
InvalidArgumentError: placeholder tensor ‘Placeholder_1‘ with dtype float and shape
今天在用tensorflow(1.15.4版本)编写代码时,报错:InvalidArgumentError: placeholder tensor 'Placeholder_1' with dtype float and shapedebug发现是我把权重初始化弄成了占位符。。。。W = tf.placeholder(tf.float32, [784, 10])改成W = tf.Variable(tf.zeros([784, 10]))...原创 2020-11-28 12:44:42 · 200 阅读 · 0 评论 -
tensorflow.examples不存在,无法载入mnist数据集
将from tensorflow.examples.tutorials.mnist import input_data替换成from tensorflow_core.examples.tutorials.mnist import input_data原创 2020-11-28 12:35:01 · 11582 阅读 · 11 评论 -
FailedPreconditionError: Attempting to use uninitialized in Tensorflow
今天用tensorflow==1.15.4版本写代码时忽然发现,FailedPreconditionError: Attempting to use uninitialized in Tensorflow恍然,需要初始化。在session建立之后先进行变量初始化。self.sess = tf.InteractiveSession()tf.global_variables_initializer().run()...原创 2020-11-28 12:32:11 · 670 阅读 · 0 评论 -
tensorflow环境变量指定gpu
指定gpu两种方式:1、设置环境变量,直接在命令行中使用,set CUDA_VISIBLE_DEVICES=1终端执行脚本,CUDA_VISIBLE_DEVICES=1 python script.py2、在程序中指定,osimport osos.environ["CUDA_VISIBLE_DEVICES"] = "5"Ref:1、https://www.jianshu.c...原创 2019-08-12 17:19:13 · 3638 阅读 · 0 评论 -
ImportError: cannot import name 'monitoring' from 'tensorflow.python.eager' 【亲测解决】
今天,在使用jiagu时import出现ImportError: cannot import name 'monitoring' from 'tensorflow.python.eager',错误原因:版本问题解决方案:pip install tensorflow==1.13.1Ref:1、 https://github.com/tensorflow/tensorflow/issu...原创 2019-08-20 15:09:08 · 7096 阅读 · 0 评论 -
模型压缩一二三之tensorflow开始压缩测试
模型压缩一二三之tensorflow模型开始压缩安装Bazel拉取tensorflow源码构建graph构建量子压缩安装Bazel具体安装见我的博客之模型压缩一二三之Bazel安装拉取tensorflow源码新建一个目录,mkdir folder;然后 cd folder;进入folder目录之后拉取tensorflow源码:git clone https://github.com/...原创 2019-07-25 19:42:01 · 486 阅读 · 0 评论 -
模型压缩一二三之tensorflow查看ckpt模型里的参数和数值
查看ckpt模型参数和数值import osfrom tensorflow.python import pywrap_tensorflowcheckpoint_path = os.path.join("<你的模型的目录>", "./model.ckpt-11000") # Read data from checkpoint filereader = pywrap_tens...原创 2019-07-25 18:43:31 · 1909 阅读 · 3 评论 -
模型压缩一二三之tensorflow图优化
tensorflow整个运行是按Graph来运行,一般是采用with方式来运行图,但图资源占用依然存在。在图运行之后加入图销毁会有助于内存释放,增加运行速度。这个在项目测试中感觉有所提升,大概提升几十毫秒左右。具体格式为:with tf.Session() as sess: ... tf.get_default_graph().finalize() # addRef...原创 2019-07-25 16:00:50 · 1007 阅读 · 0 评论 -
【亲测解决】AttributeError: module ‘tensorflow‘ has no attribute ‘__version__‘
今天在安装使用bert-as-service时报错,报错信息如下:AttributeError: module 'tensorflow' has no attribute '__version__'一看,懵逼了,啥,tensorflow么有__version__方法,打开Python解释器看下,import tensorflowtensorflow.__version__我去,还真没...原创 2019-07-29 19:02:52 · 55624 阅读 · 45 评论 -
BERT模型训练GPU,预测走cpu
最近学习BERT,训练用GPU,预测默认也走GPU,比较耗费资源,启用GPU加载也会有很多信息,想用CPU,设定如下就好:预测代码之前加入os.environ["CUDA_VISIBLE_DEVICES"]="-1"get了,game over。...原创 2019-06-28 16:38:19 · 11358 阅读 · 6 评论 -
pip 换源
有时,我们直接pip install速度会特别慢,添加源会快一些。比如,添加清华源,pip install -i https://pypi.tuna.tsinghua.edu.cn/simple <要安装的包名>。for example,pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow...原创 2019-04-27 14:06:40 · 126 阅读 · 0 评论 -
Udacity深度学习之卷积神经网络概念进阶高阶练习、可视化及其对应代码输出(加上一文详细理解卷积神经网络各个层的作用博客,正在写)
卷积神经网络练习卷积输出维度的理解problemansweranalysis卷积参数共享的理解problem设置输出层问题及解答问题1:无共享参数的卷积层参数个数提示1question1answer1analysis1问题2:有共享参数的卷积层参数个数提示2question2answer2analysis2卷积神经网络可视化卷积输出维度的理解卷积神经网络中,我们都知道一个输入后都会有一个卷积层...原创 2019-01-14 09:52:51 · 650 阅读 · 0 评论 -
深度学习之epoch
一个 epoch(代)是指整个数据集正向反向训练一次。它被用来提示模型的准确率并且不需要额外数据。本节我们将讲解 TensorFlow 里的 epochs,以及如何选择正确的 epochs。下面是训练一个模型 10 代的 TensorFlow 代码:from tensorflow.examples.tutorials.mnist import input_dataimport tensorf...转载 2018-10-28 16:44:59 · 23443 阅读 · 4 评论 -
深度学习之MiniBatch
我们先来看一个引子:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mini-batching在这一节,你将了解什么是 mini-batching,以及如何在 TensorFlow 里应用它。Mini-batching 是一个一次训练数据集的一小部分,而不是整个训练集的技术。它可以使内存较小、不能同时训练整个数据集的电脑也可以训练模型。Mini-batching 从运...原创 2018-10-28 12:18:27 · 39252 阅读 · 2 评论 -
话谈tensorflow神经网络的激活函数
神经网络激活函数有很多,我们来看下:1、我们常用激活函数是S型函数,也就是sigmod(x)。S 型函数并非是唯一可以使用的激活函数,实际上它具有一些不足。 从图中可以看出,S 型函数的导数最大值为 0.25(如上所示)。这意味着,当你用 S 型函数单元进行反向传播时,网络上每层出现的错误至少减少 75%,如果...原创 2018-10-16 07:18:39 · 389 阅读 · 0 评论 -
tensorflow-Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX A
今天从头开始学习深度学习时发现,Hello World出现错误。报:2018-10-15 23:27:11.665115: I C:\tf_jenkins\workspace\rel-win\M\windows\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that t...原创 2018-10-15 23:38:39 · 1985 阅读 · 1 评论 -
话谈tensorflow中feed_dict到底是个啥东西(理解就是python里的format,哈哈哈)
文章目录先说占位符feed_dict先说占位符 tensorflow里对于暂时不进行赋值的元素有一个称呼叫占位符。所谓占位符,顾名思义,先占着茅坑不拉屎,等需要时再赋值。所需要的命令为tf.placeholder,具体代码为:import tensorflow as tfa = tf.placeholder(tf.flo...原创 2018-10-07 15:45:38 · 33017 阅读 · 0 评论