**如下:
執行完成之後在程式目錄下生成log資料夾,儲存了網路資訊,使用tensorboard執行:# -*- coding: utf-8 -*-
import tensorflow as tf
# 影象大小
image_height = 256
image_width = 256
max_captcha = 4
char_set_len = 10
input = tf.placeholder(tf.float32, [none, image_height , image_width, 1])
# 定義cnn
def crack_captcha_cnn(x=input, w_alpha=0.01, b_alpha=0.1):
# conv layer
w_c1 = tf.variable(w_alpha * tf.random_normal([3, 3, 1, 32]))
b_c1 = tf.variable(b_alpha * tf.random_normal([32]))
conv1 = tf.nn.relu(tf.nn.bias_add(tf.nn.conv2d(x, w_c1, strides=[1, 1, 1, 1], padding='same'), b_c1))
conv1 = tf.nn.max_pool(conv1, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='same')
# fully connected layer
w_d = tf.variable(w_alpha * tf.random_normal([8 * 20 * 64, 1024]))
b_d = tf.variable(b_alpha * tf.random_normal([1024]))
dense = tf.reshape(conv1, [-1, w_d.get_shape().as_list()[0]])
dense = tf.nn.relu(tf.add(tf.matmul(dense, w_d), b_d))
w_out = tf.variable(w_alpha * tf.random_normal([1024, max_captcha * char_set_len]))
b_out = tf.variable(b_alpha * tf.random_normal([max_captcha * char_set_len]))
out = tf.add(tf.matmul(dense, w_out), b_out)
return out
# 載入網路
evaluate_net = crack_captcha_cnn()
with tf.session() as sess:
# 網路結構寫入
summary_writer = tf.summary.filewriter('./log/', sess.graph)
# summary_writer = tf.summary.filewriter('./log/', tf.get_default_graph())
print('ok')
Tensorflow卷積神經網路
卷積神經網路 convolutional neural network,cnn 是一種前饋神經網路,在計算機視覺等領域被廣泛應用.本文將簡單介紹其原理並分析tensorflow官方提供的示例.關於神經網路與誤差反向傳播的原理可以參考作者的另一篇博文bp神經網路與python實現.卷積是影象處理中一種...
Tensorflow 深層神經網路
維基百科對深度學習的定義 一類通過多層非線性變換對高複雜性資料建模演算法的合集.tensorflow提供了7種不同的非線性啟用函式,常見的有tf.nn.relu,tf.sigmoid,tf.tanh.使用者也可以自己定義啟用函式.3.1.1 交叉熵 用途 刻畫兩個概率分布之間的距離,交叉熵h越小,兩...
Tensorflow(三) 神經網路
1 前饋傳播 y x w1 b1 w2 b2 import tensorflow as tf x tf.constant 0.9,0.85 shape 1,2 w1 tf.variable tf.random normal 2,3 stddev 1,seed 1 name w1 w2 tf.vari...