小编cos*_*sst的帖子

如何在 Jupyter Notebook 中阻止 stderr 输出?

我正在 Jupyter Notebook 和我正在使用的库 (PyNN) 中运行 Python 脚本,会产生大量 stderr 输出,从而减慢代码速度并填满内存。我尝试在单元格的开头使用 %%capture 但没有任何改变,并且输出保持不变。

我正在发布输出的快照。在此输入图像描述

任何提示表示赞赏。谢谢

python stderr jupyter-notebook

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

Python:如何将 3D 图像(np 数组)重塑为 1D,然后将它们正确地重塑为 3D?

我将 RGB 图像(32 x 32 x 3)保存为 3D numpy 数组,我将其用作神经网络的输入(使用 tensorflow)。为了将它们用作输入,我使用 reshape(1,-1) 将它们重塑为一维 np 数组 (1 x 3072)。当我完成训练我的网络时,我想重新调整输出,但使用 reshape(32,32,3) 似乎没有提供所需的结果。

这是正确的方法吗?我如何确定每个数据都会回到正确的位置?

python arrays numpy image-processing tensorflow

4
推荐指数
1
解决办法
8899
查看次数

Tensorflow:我的损失函数产生巨大的数字

我正在尝试使用神经网络进行图像修复,并使用去噪自动编码器预先训练权重。全部根据https://papers.nips.cc/paper/4686-image-denoising-and-inpainting-with-deep-neural-networks.pdf

我已经制作了他们正在使用的自定义损失函数。

我的集合是图像的一批重叠补丁 (196x32x32)。我的输入是损坏的图像批次,输出应该是清理后的图像。

我的损失函数的一部分是

dif_y = tf.subtract(y_xi,y_)

dif_norm = tf.norm(dif_y, ord = 'euclidean', axis = (1,2))
Run Code Online (Sandbox Code Playgroud)

其中 y_xi(196 x 1 x 3072) 是重建的干净图像,y_ (196 x 1 x 3072) 是真实的干净图像。所以我实际上从损坏的版本中减去所有图像,然后将所有这些差异相加。我觉得这个数字很大很正常。

train_step = tf.train.AdamOptimizer().minimize(loss)
Run Code Online (Sandbox Code Playgroud)

损失值开始于 3*10^7 左右,并在 200 次运行(我循环 1000 次)后收敛于接近值。所以我的输出图像将与原始图像相差数英里。

编辑:从 3.02391e+07 开始并收敛到 3.02337e+07

有什么办法我的损失值是正确的吗?如果是这样,我怎样才能大幅减少它?

谢谢

编辑2:我的损失函数

dif_y = tf.subtract(y,y_)
dif_norm = tf.norm(dif_y, ord = 'euclidean', axis = (1,2))
sqr_norm = tf.square(dif_norm)
prod = tf.multiply(sqr_norm,0.5)
sum_norm2 = tf.reduce_sum(prod,0)
error_1 = tf.divide(sum_norm2,196)
Run Code Online (Sandbox Code Playgroud)

image-processing neural-network autoencoder deep-learning tensorflow

3
推荐指数
1
解决办法
5191
查看次数

如何在tensorflow中将RGB图像实现为张量?

我是tensorflow的新手,正在尝试创建一个堆栈式稀疏去噪自动编码器模型。我通过这里和github的示例找到了一种如何加载我的训练(和测试)集的方法,但是我无法将它们用作张量来执行所需的乘法等。(此代码仅用于加载图像)

import tensorflow as tf
import glob
import numpy as np
from PIL import Image as im

im_list = []

#LOAD ALL SETS
training_set = []
training_set = glob.glob("folder/training_set/*.jpg")

testing_set = []
testing_set = glob.glob("folder/corrupted/*.jpg") 

# testing my code only for the training set
filename_queue = tf.train.string_input_producer(training_set)

reader = tf.WholeFileReader()
key, value = reader.read(filename_queue)

#data = tf.image.decode_jpeg(value)
data = tf.decode_raw(value, tf.uint8)

sess = tf.InteractiveSession()

sess.run(tf.global_variables_initializer())
#sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())

coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)

for i in range (196):
    print i …
Run Code Online (Sandbox Code Playgroud)

python image-processing deep-learning tensorflow

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