
tensorflow
Neekity
刷出一片天
展开
-
从零开始 TensorFlow helloword
from __future__ import print_functionimport tensorflow as tfhello = tf.constant('hello, tensorflow')sess = tf.Session()print(sess.run(hello))原创 2018-12-22 16:34:19 · 159 阅读 · 0 评论 -
TensorFlow Word2vec
Word2vec 之 Skip-Gram 模型from __future__ import division, print_function, absolute_importimport collectionsimport osimport randomimport urllib.requestimport zipfileimport numpy as npimport ten...原创 2018-12-25 13:09:39 · 315 阅读 · 0 评论 -
CartPole
import numpy as npimport tensorflow as tfimport gymenv=gym.make('CartPole-v0')xs,ys,drs=[],[],[]reward_sum=0episode_number=1total_episodes=10000H=50batch_size=25learning_rate=0.1D=4gamma=...原创 2019-01-10 18:12:54 · 843 阅读 · 0 评论 -
tensorflow实现自编码器
DBNs(Deep Belief Networks)由多个限制玻尔兹曼机(Restricted Boltzmann Machines)层组成。先用自编码器的方法进行无监督的预训练,提取特征并初始化权重,然后使用标注信息进行监督式的训练。当然自编码器的作用不仅局限于给监督训练做预训练,直接使用自编码器进行特征提取和分析也是可以的。import numpy as npimport sklearn...原创 2019-01-01 20:16:30 · 1370 阅读 · 0 评论 -
tensorflow 多层感知机MLP
tf.nn.dropout(x, keep_prob)x:指输入keep_prob: 设置神经元被选中的概率import numpy as npimport sklearn.preprocessing as prepimport tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_datamni...原创 2019-01-02 15:19:41 · 341 阅读 · 0 评论 -
tensorflow CNN
卷积神经网络需要创建很多的权重和偏置,所以定义函数来重复调用。tf.nn.conv2d(x,w,strides=[1,1,1,1],padding=‘SAME’)x是输入,w是卷积的参数。w=[5,5,1,32],5*5是卷积核的尺寸,1代表通道数(灰度是1,彩色RGB是3),32代表有32个卷积核数量。strides,表示移动步长,1为不遗漏图上的每一个点。padding='SAME’表示卷...原创 2019-01-02 19:11:20 · 269 阅读 · 0 评论 -
tensorflow 保存计算图
from tensorflow.examples.tutorials.mnist import input_datamnist = input_data.read_data_sets("MNIST_data/", one_hot=True)import tensorflow as tflearning_rate=0.001batch_size=100display_step=1mod...原创 2019-01-03 10:42:42 · 1103 阅读 · 0 评论 -
tensorflow 加载计算图
加载模型时要先定义tensorflow计算图上的所有运算from tensorflow.examples.tutorials.mnist import input_datamnist = input_data.read_data_sets("MNIST_data/", one_hot=True)import tensorflow as tflearning_rate=0.001batch...原创 2019-01-03 10:44:17 · 566 阅读 · 0 评论 -
训练权重为nan
异或问题训练出来的值都是nan# -*- coding: utf-8 -*-import tensorflow as tfimport numpy as npimport matplotlib.pyplot as plttf.set_random_seed(55)np.random.seed(55)input_data = [[0., 0.], [0., 1.], [1., 0...原创 2019-01-14 15:35:15 · 773 阅读 · 0 评论 -
tensorflow cifar10 CNN
cifar10.maybe_download_and_extract() 默认在E:/tmp/中import syspath = r'E:\learn\pc_code\tensorflow\example\models-master\tutorials\image\cifar10'sys.path.append(path)import cifar10, cifar10_inputimp...原创 2019-01-09 16:17:22 · 422 阅读 · 0 评论 -
tensorflow KNN与NN之争
看了很多tensorflow 的KNN代码,基本就是下面原版代码的变种。很多人认为Xtr, Ytr = mnist.train.next_batch(5000) #5000 for training (nn candidates)这行代码就是超参数K=5000. 但我仍有疑问以下是我的见解,不正之处请指出。不知道是不是该这样理解。它这里选了5000个训练样本,200个测试样本。然后遍历200个测...原创 2019-01-03 20:59:29 · 1084 阅读 · 0 评论 -
kaggle tensorflow 泰坦尼克 逻辑回归
import pandas as pdimport numpy as npimport tensorflow as tf from sklearn import preprocessingfrom tensorflow.contrib.tensor_forest.python import tensor_forestfrom tensorflow.python.ops import re...原创 2018-12-29 15:02:32 · 260 阅读 · 0 评论 -
从零开始 TensorFlow 立即进行符号运算
from __future__ import absolute_import, division, print_functionimport numpy as npimport tensorflow as tfimport tensorflow.contrib.eager as tfetfe.enable_eager_execution()a = tf.constant(2)pr...原创 2018-12-22 17:52:16 · 284 阅读 · 0 评论 -
从零开始 TensorFlow session进行符号运算
from __function__ import print_function import tensorflow as tf a=tf.constant(2)b=tf.constant(3)with tf.Session() as sess: print('sess run ... a+b result: %i' % sess.run(a+b)) print('sess run .....原创 2018-12-22 18:56:20 · 215 阅读 · 0 评论 -
从零开始 TensorFlow RandomForest
tf.reset_default_graph() 注意要重新设置一下图from __future__ import print_functionimport tensorflow as tffrom tensorflow.contrib.tensor_forest.python import tensor_forestfrom tensorflow.python.ops import r...原创 2018-12-28 14:04:43 · 607 阅读 · 0 评论 -
kaggle上泰坦尼克的年龄使用tensorflow进行随机森林回归
kaggle上泰坦尼克的年龄使用随机森林分类为什么准确率只有0.47import pandas as pdimport numpy as npimport tensorflow as tf from tensorflow.contrib.tensor_forest.python import tensor_forestfrom tensorflow.python.ops import ...原创 2018-12-28 15:23:22 · 1157 阅读 · 2 评论 -
TensorFlow NN
from __future__ import print_functionimport numpy as npimport tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_datamnist=input_data.read_data_sets("/tmp/data/",one_hot=True)...原创 2018-12-23 15:59:40 · 223 阅读 · 0 评论 -
TensorFlow线性回归
from __future__ import print_functionimport tensorflow as tfimport numpy as npimport matplotlib.pyplot as pltnr=np.randomlearning_rate = 0.01training_epochs=1000display_step=50train_X = np.a...原创 2018-12-23 17:05:06 · 132 阅读 · 0 评论 -
TensorFlow softmax回归
tf.cast 是转换类型from __future__ import print_functionimport tensorflow as tfimport numpy as npimport matplotlib.pyplot as pltfrom tensorflow.examples.tutorials.mnist import input_datamnist=input_da...原创 2018-12-23 20:39:06 · 216 阅读 · 0 评论 -
TensorFlow kmeans
tf.nn.embedding_lookup:tf.nn.embedding_lookup()就是根据input_ids中的id,寻找embeddings中的第id行。比如input_ids=[1,3,5],则找出embeddings中第1,3,5行,组成一个tensor返回。num_steps=500batch_size=1024k=25num_classes=10num_featu...原创 2018-12-24 11:03:09 · 443 阅读 · 1 评论 -
tensorflow Tensorboard可视化
tensorboard --logdir=绝对路径import tensorflow as tffrom tensorflow.examples.tutorials.mnist import input_datamnist = input_data.read_data_sets("MNIST_data/", one_hot=True)import oslearning_rate = 0....原创 2019-01-03 17:14:38 · 184 阅读 · 0 评论 -
cross_entry的设置tensorflow 权重更新为nan的问题
cross_entry的设置tensorflow 权重更新为nan的问题当用cifar10时,cross_entry=tf.reduce_mean(-tf.reduce_sum(y*tf.log(ylog),reduction_indices=1))无法更新权重,cross_entry=tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(...原创 2019-01-22 17:14:01 · 572 阅读 · 0 评论