tensorflow
cousinmary
这个作者很懒,什么都没留下…
展开
-
saver 保存读取
用tensorflow 保存变量import tensorflow as tfimport numpy as np# save to file#remember to define the same dtype and shape when restoreW=tf.Variable([[1, 2, 3], [4, 5, 6]], dtype=tf.float32, name='Weights') # 最好给个dtypeb=tf.Variable([[1, 2, 3]], dtype=tf.f原创 2021-05-30 14:12:03 · 150 阅读 · 0 评论 -
CNN,2 conv layer,2 pooling layer
import tensorflow as tfimport numpy as npfrom tensorflow.examples.tutorials.mnist import input_data#number 1 to 10 datamnist=input_data.read_data_sets('MNIST_data',one_hot=True)def compute_accuracy(v_xs,v_ys): global prediction #全局变量 y_pre=s原创 2021-04-11 22:11:18 · 229 阅读 · 0 评论 -
classification
仅有输入和输出层,无隐藏层import tensorflow as tfimport numpy as npfrom tensorflow.examples.tutorials.mnist import input_datamnist=input_data.read_data_sets('MNIST_data',one_hot=True)def compute_accuracy(v_xs,v_ys): global prediction #全局变量 y_pre=sess.r原创 2021-04-11 10:32:00 · 56 阅读 · 0 评论 -
dropout防止overfitting
#使用sklearn之前要装scikit-learn这个包from sklearn.datasets import load_digitsfrom sklearn.model_selection import train_test_splitfrom sklearn.preprocessing import LabelBinarizer#load datadigits=log_digits()X=digits.data #加载从0到9的digits datey=digits.target #原创 2021-04-09 21:51:29 · 101 阅读 · 0 评论 -
tensorboard 添加histogram、scalar
添加输入def add_layer(inputs,in_size,out_size,n_layer,activation_function=None): layer_name='layer%s'%n_layer#输出结果为layern_layer,以字符串形式编辑神经层 tf.summary.histogram(layer_name+'weights',Weights)#纵轴是weights,表示的是Weights tf.summary.histogram(layer_name+'.原创 2021-04-05 22:24:46 · 392 阅读 · 0 评论 -
tensorboard可视化
inputs可视化with tf.name_scope('inputs'): xs=tf.placeholder(tf.float32,[None,1],name='x_input')#None是无论给多少sample都OK ys=tf.placeholder(tf.float32,[None,1],name='y_input')hidden layer可视化def add_layer(inputs,in_size,out_size,activation_function=.原创 2021-04-05 20:50:01 · 172 阅读 · 2 评论 -
可视化plot result
import tensorflow as tfimport numpy as npimport matplotlib.pyplot as plt#添加神经层def add_layer(inputs,in_size,out_size,activation_function=None): Weights=tf.Variable(tf.random_normal([in_size,out_size]))#用random比用0好 biases=tf.Variable(tf.zeros原创 2021-04-02 13:02:08 · 1051 阅读 · 0 评论 -
创建简单神经网络
import tensorflow as tfimport numpy as np#添加神经层def add_layer(inputs,in_size,out_size,activation_function=None): Weights=tf.Variable(tf.random_normal([in_size,out_size]))#用random比用0好 biases=tf.Variable(tf.zeros([1,out_size])+0.1) #biases推荐的值不为原创 2021-04-02 11:35:07 · 135 阅读 · 3 评论 -
add layer
import tensorflow as tf#添加神经层def add_layer(inputs,in_size,out_size,activation_function=none) Weights=tf.Variable(tf.random_normal[in_size,out_size])#用random比用0好 biases=tf.Variable(tf.zeros([1,out_size])+0.1) #biases推荐的值不为0 Wx_plus_b=tf.matm原创 2021-04-01 21:57:56 · 180 阅读 · 0 评论 -
placeholder&feed_dict
import tensorflow as tfinput1=tf.placeholder(tf.float32)#一般处理float 32input2=tf.placeholder(tf.float32)output=tf.multiply(input1,input2)with tf.Session() as sess: print(sess.run(output,feed_dict={input1:[7.],input2:[2.]})) #placeholder用于占位,fee原创 2021-04-01 21:02:18 · 93 阅读 · 0 评论 -
variable in python
import tensorflow as tfstate=tf.Variable(0,name='counter')#定义变量state,初始值为0,名字是'counter'one=tf.constant(1)new_value=tf.add(state,one)update=tf.assign(state,new_value)#把new_value的值赋给stateinit=tf.initialize_all_variables()#定义变量必备with tf.Session() as se原创 2021-04-01 16:27:23 · 100 阅读 · 0 评论 -
简单神经网络,来自莫烦
import tensorflow as tfimport numpy as np#creat datax_data=np.random.rand(100).astype(np.float32)y_data=x_data*0.1+0.3#创建y=0.1x+0.3###creat tensorflow structure start###Weights=tf.Variable(tf.random_uniform([1],-1.0,1.0))#random,服从[-1,1]正态分布biase原创 2021-03-28 18:34:58 · 78 阅读 · 0 评论