【TensorFlow】【算子解析】【tf.nn】tf.nn.relu_layer

【算子功能描述】fetch

tf.nn.relu_layer(
    x,          // 2D [batch, in_units]
    weights,    //  2D [batch, out_units]
    biases,     // 1D [out_units]
    name=None
)

計算公式爲: relu(matmul(x, weights) + biases). 輸出shape爲[batch, out_units]code

【示例代碼】blog

# -*- coding:utf-8 -*-
import tensorflow as tf
import numpy as np

img = np.reshape(np.asarray(list(range(3*5))).astype(np.float32),newshape=(3,5))
weight = np.reshape(np.asarray(list(range(5*3))).astype(np.float32),newshape=(5,3))
bias = np.reshape(np.asarray(list(range(3))).astype(np.float32),newshape=(3,))

x = tf.placeholder(shape=(3,5),dtype=tf.float32)
y = tf.placeholder(shape=(5,3),dtype=tf.float32)
z = tf.placeholder(shape=(3,),dtype=tf.float32)
y1 = tf.nn.relu_layer(x,y,z)
with tf.Session() as sess:
    out= sess.run(fetches=y1,feed_dict={x:img,y:weight,z:bias})
    print(out)
    tf.train.write_graph(graph_or_graph_def=sess.graph,logdir="./",name="./model/relu_layer.pb",as_text=False)

【模型以下】utf-8

相關文章
相關標籤/搜索