重塑Keras图层 [英] Reshaping Keras layers

查看:58
本文介绍了重塑Keras图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入图像416x416.如何创建4 x 10的输出,其中4是列数,10是行数?

I have an input image 416x416. How can I create an output of 4 x 10, where 4 is number of columns and 10 the number of rows?

我的标签数据是4列10行的2D数组.

My label data is 2D array with 4 columns and 10 rows.

我知道reshape()方法,但是它要求生成的形状与输入的元素数量相同.

I know about the reshape() method but it requires that the resulted shape has same number of elements as the input.

使用416 x 416的输入大小和最大的池层,我可以获得最大的13 x 13输出.

With 416 x 416 input size and max pools layers I can get max 13 x 13 output.

是否有一种方法可以在不丢失数据的情况下实现4x10输出?

Is there a way to achieve 4x10 output without loss of data?

我的输入标签数据看起来像

My input label data looks like for example like

[[  0   0   0   0]
 [  0   0   0   0]
 [  0   0   0   0]
 [  0   0   0   0]
 [  0   0   0   0]
 [  0   0   0   0]
 [  0   0   0   0]
 [116  16 128  51]
 [132  16 149  52]
 [ 68  31  77  88]
 [ 79  34  96  92]
 [126  37 147 112]
 [100  41 126 116]]

这表示我要检测的图像上有6个对象,第一个值为xmin,第二个ymin,第三个xmax,第四个ymax.

Which indicates there are 6 objects on my images that i want to detect, first value is xmin, second ymin , third xmax, fourth ymax.

我的网络的最后一层看起来像

The last layer of my networks looks like

(None, 13, 13, 1024)

推荐答案

首先将(None, 13, 13, 1024)层展平

model.add(Flatten())

它将给出13*13*1024=173056

一维张量

然后添加一个密集层

model.add(Dense(4*10))它将输出为40

这会将您的3D形状转换为1D

this will transform your 3D shape to 1D

然后只需调整大小即可满足您的需求

then simply resize to your needs

model.add(Reshape(4,10))

这将起作用,但绝对会破坏数据的空间性质

This will work but will absolutely destroy the spatial nature of your data

这篇关于重塑Keras图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆