第五步:成本函数
- def compute_cost(y_conv,Y):
- cost=tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=y_conv,labels=Y))
- return cost
第六步:梯度降低更新参数
第七步:练习模型
- def model(X_train,Y_train,X_test,Y_test,learning_rate=0.001,num_epochs=20,minibatch_size=32,print_cost=True):
- ops.reset_default_graph() #(1080, 64, 64, 3)
- tf.set_random_seed(1) #Y_train(6, 1080)
- seed=3
- (m,num_px1,num_px2,c)=X_train.shape
- n_y=Y_train.shape[0]
- costs=[]
- X,Y=create_placeholder(64,3,6)
- parameters=initialize_parameters()
- Z3=forward_propagation(X,parameters)
- cost=compute_cost(Z3,Y)
- optm=tf.train.AdamOptimizer(learning_rate).minimize(cost)
- correct_prediction=tf.equal(tf.argmax(Z3,1),tf.argmax(Y,1))#居然忘记1了,所以一向出现损掉越来越小了,然则精确率却一向是0
- accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
- with tf.Session() as sess:
- tf.global_variables_initializer().run()
- for epoch in range(num_epochs):
- epoch_cost=0
- num_minibatches=int(m/minibatch_size)
- seed+=1
- #下面输入请求(6,,1080)格局,所以要加个转置
推荐阅读
Tech Neo技巧沙龙 | 11月25号,九州云/ZStack与您一路商量云时代收集界线治理实践 最终,只有一条链会被保存下>>>详细阅读
本文标题:深入浅出解读卷积神经网络
地址:http://www.17bianji.com/lsqh/39218.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示