小编Ser*_* S.的帖子

TensorFlow张量中最大元素的索引

如何在TensorFlow中获取沿选定轴的张量最大元素的索引?

linear-algebra tensorflow

5
推荐指数
1
解决办法
4298
查看次数

Python,OpenCV:增加图像亮度而不会溢出UINT8数组

我正在尝试增加灰度图像的亮度.cv2.imread()返回一个numpy数组.我正在为数组的每个元素添加整数值.从理论上讲,这会增加每一个.之后,我可以将上限阈值设为255,并获得更高亮度的图像.

这是代码:

grey = cv2.imread(path+file,0)

print type(grey)

print grey[0]

new = grey + value

print new[0]

res = np.hstack((grey, new))

cv2.imshow('image', res)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

但是,内部OpenCV例程显然是这样的:

new_array = old_array % 255
Run Code Online (Sandbox Code Playgroud)

高于255的每个像素强度值变为除以255的余数.

结果,我变得黑暗而不是完全变白.

这是输出:

<type 'numpy.ndarray'>
[115 114 121 ..., 170 169 167]
[215 214 221 ...,  14  13  11]
Run Code Online (Sandbox Code Playgroud)

这是图像:

在此输入图像描述

如何关闭此余数机制?有没有更好的方法来提高OpenCV的亮度?

python arrays opencv numpy image-processing

5
推荐指数
2
解决办法
1万
查看次数

tensorflow:简单LSTM网络的共享变量错误

我正在尝试构建一个最简单的LSTM网络.只是希望它预测序列中的下一个值np_input_data.

import tensorflow as tf
from tensorflow.python.ops import rnn_cell
import numpy as np

num_steps = 3
num_units = 1
np_input_data = [np.array([[1.],[2.]]), np.array([[2.],[3.]]), np.array([[3.],[4.]])]

batch_size = 2

graph = tf.Graph()

with graph.as_default():
    tf_inputs = [tf.placeholder(tf.float32, [batch_size, 1]) for _ in range(num_steps)]

    lstm = rnn_cell.BasicLSTMCell(num_units)
    initial_state = state = tf.zeros([batch_size, lstm.state_size])
    loss = 0

    for i in range(num_steps-1):
        output, state = lstm(tf_inputs[i], state)
        loss += tf.reduce_mean(tf.square(output - tf_inputs[i+1]))

with tf.Session(graph=graph) as session:
    tf.initialize_all_variables().run()

    feed_dict={tf_inputs[i]: np_input_data[i] for i in range(len(np_input_data))} …
Run Code Online (Sandbox Code Playgroud)

python neural-network lstm tensorflow

3
推荐指数
2
解决办法
6167
查看次数