首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pybrain简单前馈网络不输出期望值

Pybrain简单前馈网络不输出期望值
EN

Stack Overflow用户
提问于 2015-12-17 15:31:22
回答 1查看 171关注 0票数 1

我正在尝试使用pybrain输出rgb值。输入层采用rgb值数组,所有隐藏层都是线性模型。我原以为网络会输出rgb值。但是,这个网络的输出结果是一个值数组,这些值在0:255的范围内是不接近的。这些图像大约有25种不同的.jpg图像一头公牛。每个图像都是长度为575280的扁平数组。我希望网络能汇聚到一张像公牛一样的图像上。

代码语言:javascript
复制
import numpy as np
from pybrain.structure import FeedForwardNetwork, LinearLayer, SigmoidLayer, GaussianLayer, TanhLayer
from pybrain.structure import FullConnection, BiasUnit
import testabull

bull_x = 510
bull_y = 398
bull_flat = 575280

n = FeedForwardNetwork()

bias_unit = BiasUnit()
in_layer = LinearLayer(bull_flat)
hidden_A = LinearLayer(5)
hidden_B = LinearLayer(10)
out_layer = LinearLayer(bull_flat)

n.addInputModule(in_layer)
n.addModule(hidden_A)
n.addModule(hidden_B)
n.addOutputModule(out_layer)
n.addModule(bias_unit)

in_to_hidden = FullConnection(in_layer, hidden_A)
hidden_to_hidden = FullConnection(hidden_A, hidden_B)
hidden_to_out = FullConnection(hidden_B, out_layer)
bias_to_hidden = FullConnection(hidden_B, out_layer)

n.addConnection(in_to_hidden)
n.addConnection(hidden_to_hidden)
n.addConnection(bias_to_hidden)
n.addConnection(hidden_to_out)

n.sortModules()


bull_img_array = testabull.crop_the_bull_images('../../imgs/thebull/')

trainable_array = [] ## an array of flattened images
for im in bull_img_array:
    flat_im = np.array(im).flatten()
    trainable_array.append(flat_im)

print n
print n.activate(trainable_array[0])

output = None
for a in trainable_array:
    output = n.activate(a)
print output, len(output) 

如果有人有任何建议的话,我会很棒的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-17 16:00:26

首先,这里有两个问题,一个是您需要在0到255之间扩展输出。您可以在此之后进行一些转换。取最大值和最小值,然后在0到255之间换位。

另一方面,这个网络很可能不会知道你想要它做什么,你的隐藏层正在使用线性层。这不是很有用,因为权重本身形成了一个线性变换。你最终会得到一个线性函数。演戏

我建议对隐藏层使用SigmoidLayer,这当然会压缩0到1之间的值,可以通过将输出层中的值乘以255来纠正这一点。要么通过一个固定的层,要么只是转换之后的值。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34338319

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档