![](https://img-blog.csdnimg.cn/20190912105209535.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
TensorFlow
肯德基套餐
这个作者很懒,什么都没留下…
展开
-
获取tensorflow中各个tensor的名字
原文:https://stackoverflow.com/questions/36883949/in-tensorflow-get-the-names-of-all-the-tensors-in-a-graphI’ll try to summarize the answers:To get all nodes in the graph: (type tensorflow.core.framework.node_def_pb2.NodeDef)To get all ops in the graph: (ty原创 2022-06-10 08:41:29 · 453 阅读 · 1 评论 -
AttributeError: module ‘tensorflow‘ has no attribute ‘Session‘
问题:解决:https://stackoverflow.com/questions/55142951/tensorflow-2-0-attributeerror-module-tensorflow-has-no-attribute-session原创 2022-06-06 11:00:05 · 89 阅读 · 0 评论 -
tensorflow_datasets.core.features‘ has no attribute ‘text‘
FYIhttps://github.com/tensorflow/datasets/issues/2647Indeed, the API is deprecated. Please use tfds.deprecated.text or update your code to use tensorflow_text https://www.tensorflow.org/datasets/api_docs/python/tfds/deprecated/text原创 2022-04-07 09:51:41 · 363 阅读 · 0 评论 -
Only Size-1 Arrays Can Be Converted To Python Scalars Error
参考https://www.pythonpool.com/only-size-1-arrays-can-be-converted-to-python-scalars-error-solved/原创 2021-07-14 15:29:38 · 666 阅读 · 0 评论 -
vscode tf2.0无法自动补全问题
workspace的setting中加上"python.autoComplete.extraPaths": ["/Users/xx/opt/anaconda3/envs/tensorflowcpu_env/lib/python3.7/site-packages/"]注意后面是个数组,之前参考了这个链接,起始没必要(改__init__文件)https://github.com/tensorflow/tensorflow/issues/32982...原创 2021-04-06 11:23:52 · 1273 阅读 · 0 评论 -
Initializing libiomp5.dylib, but found libiomp5.dylib already initialized.
加上import osos.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"原创 2021-04-02 15:51:04 · 179 阅读 · 0 评论 -
tf.keras.losses.SparseCategoricalCrossentropy
交叉熵损失函数tf.keras.losses.SparseCategoricalCrossentropy( from_logits=False, reduction=losses_utils.ReductionV2.AUTO, name='sparse_categorical_crossentropy')y_pred为N维向量(N为类别的个数),label为单个数字,如果label也是one-hot之后的值,需要使用CategoricalCrossentropy损失函数。参数:原创 2020-06-23 10:06:07 · 14034 阅读 · 1 评论 -
tensorflow数据batch化训练模板
定义产生batch数据的函数# 定义产生bacth数据的函数def get_batch_data(): data_x, data_y = gen_data(10**4) data_x, data_y = tf.constant(data_x), tf.constant(data_y) input_queue = tf.train.slice_input_producer...原创 2020-04-23 20:57:12 · 450 阅读 · 0 评论 -
tf.argmax()函数
根据axis来选出最大值的索引,axis=0表示按列,axis=1表示按行array = tf.constant([[1,2,3],[4,0,6]])with tf.Session() as sess: print(sess.run(tf.arg_max(array, 0))) #[101] print(sess.run(tf.arg_max(array, 1))) ...原创 2020-04-23 01:03:47 · 225 阅读 · 0 评论 -
tf.truncated_normal_initializer用法
tf.compat.v1.truncated_normal_initializer( mean=0.0, stddev=1.0, seed=None, dtype=tf.dtypes.float32)These values are similar to values from a random_normal_initializer except that values more t...原创 2020-04-22 22:09:15 · 2775 阅读 · 1 评论 -
tf.Dataset.shuffle
shuffle( buffer_size, seed=None, reshuffle_each_iteration=None)buffer_size参数,指元素的个数,最完美的shuffle是所有数据一起shuffle,但是避免内存不够,每次选buffer_size个数据进行shuffle。比如Dataset一共10000个元素,buffer_size=1000, ...原创 2020-01-02 09:58:24 · 4094 阅读 · 0 评论 -
LC.1177. Can Make Palindrome from Substring
class Solution(object): def canMakePaliQueries1(self, s, queries): """ straight forward 方法,每个query的时候统计每个char的Count count 为奇数的个数 // 2 <= change 即满足 超时 "...原创 2019-10-03 12:48:53 · 140 阅读 · 0 评论 -
TF入门之双向LSTM
参考资料https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/bidirectional_rnn.pyimport tensorflow as tffrom tensorflow.contrib import rnnimport numpy as npfrom...原创 2019-07-23 15:45:32 · 852 阅读 · 0 评论 -
TF 菜鸡入门(一)
例子import tensorflow as tfimport numpy as npx_data = np.random.rand(100).astype(np.float32)y_data = x_data*3 + 0.3# Variable 表示可变,可训练变量Weights = tf.Variable(tf.random_uniform([1], -1.0, 1.0))bi...原创 2019-07-01 22:20:47 · 922 阅读 · 0 评论 -
TF入门之一元线性回归
source fromhttps://github.com/aymericdamien/TensorFlow-Examples/import tensorflow as tfimport numpyimport matplotlib.pyplot as pltrng = numpy.randomlearning_rate = 0.01training_epochs = 1000d...原创 2019-07-13 09:24:02 · 114 阅读 · 0 评论 -
TF入门之逻辑回归
source from https://github.com/aymericdamien/TensorFlow-Examples/import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_datafrom tensorflow.examples.tutorials.mnist import i...原创 2019-07-13 10:56:44 · 485 阅读 · 0 评论 -
TF reduction_indices用法
reduction_indices表示按照某个维度进行操作,经常用到2维以内的,三维以上的比较复杂暂不讨论array = np.array([[1,2,3],[4,5,6]])with tf.Session() as sess: print(sess.run(tf.reduce_sum(array, reduction_indices=1))) print(sess.run(tf....原创 2019-07-13 11:08:16 · 2201 阅读 · 0 评论 -
TF入门之最邻近算法
source from https://github.com/aymericdamien/TensorFlow-Examples/import numpy as npimport tensorflow as tf# 通过最邻近的点来决定样本的种类,没有训练过程吗,就是求最小距离from tensorflow.examples.tutorials.mnist import input_da...原创 2019-07-13 13:04:17 · 192 阅读 · 0 评论 -
tf.nn.embedding_lookup用法
tf.nn.embedding_lookup(lookup_array, index_array)返回lookup_array中以index_array中值为下标的值array = np.array([2,0,1])look_up = np.array([4,5,6])res = tf.nn.embedding_lookup(look_up, array)with tf.Session(...原创 2019-07-13 21:04:19 · 790 阅读 · 0 评论 -
tf.contrib.factorization.KMeans 详解
API https://www.tensorflow.org/api_docs/python/tf/contrib/factorization/KMeans__init__( inputs, 输入张量 num_clusters, 簇的个数,如果initial_clusters为张量那么该参数就无效,簇的个数为张量的长度 initial_cluster...原创 2019-07-13 21:07:48 · 1203 阅读 · 0 评论 -
TF入门之自编码器
参考资料:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/3_NeuralNetworks/autoencoder.pyimport tensorflow as tfimport numpy as npimport matplotlib.pyplot as pltfrom tensorf...原创 2019-07-24 14:56:43 · 394 阅读 · 0 评论 -
TF入门之模型的保存与读取
参考资料:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/4_Utils/save_restore_model.pyfrom tensorflow.examples.tutorials.mnist import input_dataimport tensorflow as tfmnist =...原创 2019-07-24 16:34:55 · 2650 阅读 · 0 评论 -
TF入门之LSTM
import tensorflow as tffrom tensorflow.contrib import rnn# Import MNIST datafrom tensorflow.examples.tutorials.mnist import input_datamnist = input_data.read_data_sets("/tmp/data/", one_hot=True)...原创 2019-07-23 13:53:22 · 1296 阅读 · 0 评论 -
TypeError: __init__() got an unexpected keyword argument 'shape'
tensorFlow入门书籍中的代码import tensorflow as tfg1 = tf.Graph()with g1.as_default(): v = tf.get_variable("v", initializer=tf.zeros_initializer(shape=[1]))g2 = tf.Graph()with g2.as_default(): v...原创 2018-12-04 19:33:22 · 10692 阅读 · 0 评论