我在CrossValidation上就图像解释提出了类似的问题。我将我的详细问题移到此处以包含一些代码详细信息。
我得到的结果并不完全理想所以也许你以前遇到过这个问题,你可以帮我找出来。
它是完全卷积神经网络“没有完全连接的部分”。
培训部分
首先将图像转置以匹配卷积函数。(batch_no,img_channels,宽度,高度)
input.transpose(0, 3, 1, 2)
使用学习率优化学习:3e-6,Hu_uniform 初始化和嵌套 500 个 epoch,直到收敛。
- 培训费用:1.602449
- 训练损失:4.610442
- 验证错误:5.126761
- 测试损失:5.885714
后向部分
加载图像
jpgfile = np.array(Image.open(join(testing_folder,img_name)))
重塑为一批
batch = jpgfile.reshape(1, jpgfile.shape[0], jpgfile.shape[1], 3)
使用 Relu 运行模型以在激活后提取第一个特征图
output = classifier.layer0.output
Test_model = theano.function(
inputs=[x],
outputs=output,
)
layer_Fmaps = Test_model(test_set_x)
应用 backwork 模型使用唯一激活的神经元重建图像
bch, ch, row, col = layer_Fmaps.shape
output_grad_reshaped = layer_Fmaps.reshape((-1, 1, row, col))
output_grad_reshaped = output_grad_reshaped[0].reshape(1,1,row,col)
input_shape = (1, 3, 226, 226)
W = classifier.layer0.W.get_value()[0].reshape(1,3,7,7)
kernel = theano.shared(W)
inp = T.tensor4('inp')
deconv_out = T.nnet.abstract_conv.conv2d_grad_wrt_inputs(
output_grad = inp,
filters=kernel,
input_shape= input_shape,
filter_shape=(1,3,7,7),
border_mode=(0,0),
subsample=(1,1)
)
f = theano.function(
inputs = [inp],
outputs= deconv_out)
f_out = f(output_grad_reshaped)
deconved_relu = T.nnet.relu(f_out)[0].transpose(1,2,0)
deconved = f_out[0].transpose(1,2,0)
这里我们有两个图像结果,第一个是没有激活的转置图像,第二个是 relu,因为内核可能有一些负权重。
从转置的卷积图像中可以清楚地看出,该内核学习检测与该图像相关的一些有用特征。但是重建部分在转置卷积期间破坏了图像配色方案。这可能是因为像素值是小的浮点数。你知道这里的问题在哪里吗?