简体   繁体   中英

threre are four nodes in output layer, but I want to use one of the node' s output, how can I fix it?

Code of the output layer:

Weights1 = tf.Variable(tf.random_normal([11, 4]))

biases1 = tf.Variable(tf.zeros([1, 4]) + 0.1)
Wx_plus_b1 = tf.matmul(l0, Weights1) + biases1

N1act = 2/(1+pow(math.e,-Wx_plus_b1[3]))-1 

I want to use output of the fourth node

This is my custom activation function, it only needs one input.

prediction = tf_spiky(N1act) 

Error info:

raise ValueError(err.message)

ValueError: slice index 3 of dimension 0 out of bounds. for 'strided_slice' (op: 'StridedSlice') with input shapes: [1,4], [1], [1], [1] and with computed input tensors: input[1] = , input[2] = , input[3] = .

Both tf.matmul(l0, Weights1) and biases1 has shape [1,4], and consequently so does Wx_plus_b1 . That is, Wx_plus_b1 is a matrix with one row and four columns. When you write Wx_plus_b1[3] you are selecting row number 4 of Wx_plus_b1 which does not exist, hence the error. The value you are looking for is actually Wx_plus_b1[0,3] , ie the value in the fourth column of the first row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM