- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试对灰色图像进行训练。 batch_size = 32, image size = (48*48)
.
我定义我的网络 input_shape = (48,48,1)
.训练网络时出现如下错误。
错误 :
ValueError: Error when checking input: expected conv2d_17_input to have 4 dimensions, but got array with shape (32, 48, 48)
model.add(Conv2D(32, kernel_size=(5, 5),
activation='relu',
input_shape=(48,48,1)
)
)
最佳答案
假设您有 1000
训练图像,其中每个图像是 48x48
灰度。将图像加载到 numpy 数组中后,您将得到以下形状:(1000, 48, 48)
.
这实质上意味着您有 1000
数组中的元素,每个元素都是 48x48
矩阵。
现在为了提供这些数据来训练 CNN
,您必须将此列表 reshape 为 (1000, 48, 48, 1)
哪里1
代表 channel 维度。由于您使用的是灰度图像,因此您必须使用 1
.如果是 RGB,它将是 3
.
考虑下面给出的玩具示例,
x_train = np.random.rand(1000, 48, 48) #images
y_train = np.array([np.random.randint(0, 2) for x in range(1000)]) # labels
# simple model
model = Sequential()
model.add(Conv2D(32, kernel_size=(5, 5),
activation='relu',
input_shape=(48,48,1)
)
)
model.add(Flatten())
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam')
# fitting model
model.fit(x_train, y_train, epochs=10, batch_size=32)
Error when checking input: expected conv2d_3_input to have 4 dimensions, but got array with shape (1000, 48, 48)
x_train
像这样,
x_train = x_train.reshape(x_train.shape[0], x_train.shape[1], x_train.shape[2], 1)
model.fit(x_train, y_train, epochs=10, batch_size=32)
Epoch 1/10
1000/1000 [==============================] - 1s 1ms/step - loss: 0.7177
Epoch 2/10
1000/1000 [==============================] - 1s 882us/step - loss: 0.6762
Epoch 3/10
1000/1000 [==============================] - 1s 870us/step - loss: 0.5882
Epoch 4/10
1000/1000 [==============================] - 1s 888us/step - loss: 0.4588
Epoch 5/10
1000/1000 [==============================] - 1s 906us/step - loss: 0.3272
Epoch 6/10
1000/1000 [==============================] - 1s 910us/step - loss: 0.2228
Epoch 7/10
1000/1000 [==============================] - 1s 895us/step - loss: 0.1607
Epoch 8/10
1000/1000 [==============================] - 1s 879us/step - loss: 0.1172
Epoch 9/10
1000/1000 [==============================] - 1s 886us/step - loss: 0.0935
Epoch 10/10
1000/1000 [==============================] - 1s 888us/step - loss: 0.0638
关于keras - 我如何在 keras 中使用带有灰度图像的神经网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55572325/
有谁知道是否有办法在悬停时使图像灰度 - 除了创建 2 个单独的图像并更改 src 之外。 谢谢 编辑 - 半工作代码...: $(document).ready(function() {
我正在使用 flexbox 构建一个网站,其中包含 16x9 视频缩略图的 3 乘任意网格。我想在彩色缩略图变成单调(灰度 + x% 透明颜色层)的地方创建翻转,上面有一个白色 Logo 。 尽管我尽
现在泰国很多网站都是灰度的,大多使用-webkit-filter: grayscale(100%), filter: grayscale(100%)等。 我知道我们可以像往常一样“手动”(在 Chro
给定一张灰度的图像,我如何获得该位置的灰度像素值? 这始终将 temp 输出为 -16777216(黑色)。 public void testMethod() { int width = im
灰度化一个可绘制对象: ColorMatrix matrix = new ColorMatrix(); matrix.setSaturation(200); ColorMatrixColorFilte
我正在尝试创建一种悬停效果,其中图像以全彩色开始,当我将鼠标悬停在图像上时,我希望它有一个蓝色覆盖层。 事实是,只有一个简单的蓝色叠加层,它只是在彩色图像之上放置一个半透明的蓝色 block ……这意
将颜色 Drawable 转换为灰度的正确方法是什么(表示禁用状态)? 编辑: 黑白 => 灰度 最佳答案 我知道这个问题是不久前提出的,但我遇到了一个更简单的解决方案,如果你有一个 Drawable
我需要将 CMYK 图像转换为灰度 CMYK 图像。起初我以为我可以使用与 RGB -> 灰度转换相同的方法,比如 (R + G + B)/3 或 max(r, g, b)/2 + min(r, g,
我遇到了一些将 UIImage 更改为灰度的代码的问题。它可以在 iPhone/iPod 上正常工作,但在 iPad 上,任何已经绘制的内容都会在此过程中被拉伸(stretch)和扭曲。 它有时也只在
假设我有: int x = 140; 我想得到的结果: int y = new Color(x, x, x).getRGB() 来自 Java API 文档: getRGB() Gets the RG
我在我的论文中使用 opencv 用 c++ 编写了一个 block 匹配算法。它正在处理灰度图片并通过其绝对像素地址寻址 IPLImage。 我必须将 IPLImage 分成相同大小的 block
我有一个带有背景图像的 div,我正在使用过滤器以黑白方式显示它 (filter: grayscale(100%);)。我现在正试图在该 div 中放置一个颜色图标。尝试将图标设置为 grayscal
我会避免使用 cvtColor(frame, image, CV_RGB2GRAY); 转换摄像机拍摄的每一帧无论如何设置 VideoCapture 直接进入灰度? 例子: VideoCapture
我有一些 CSS 可以将我的图像变成灰度(带有一些用于 Firefox 的 svg) img.grayscale{ filter: grayscale(100%);
有没有什么方法可以在不丢失任何其他功能的情况下以灰度显示 Google map (通过 Javascript API 嵌入)? 最佳答案 是的,他们在 API 的 V3 中引入了 StyledMaps
我正在使用 Java Swing 制作桌面应用程序。 在我的应用程序中,我对 16 位灰度和 tiff 图像进行了一些图像处理。 在我的应用程序中,用户可以通过将图像拖放到 JDesktopPane
我正在为学校的一个项目执行此操作,稍后将添加更多功能,但我在完成基本设置时遇到了困难。 我最初尝试在 C++ 中执行此操作,但在阅读了有关 BufferedImage 的一些文档后决定切换到 Java
我使用 Canvas 更改网页上图像的颜色(本例为灰度)。但是,通过使用以下代码,仅更改了最后一张图像。 但我想更改网页上所有图像的颜色 $(function(){ var theI
首先我要警告你,我只是一个试图让事情发挥作用的物理学家,我对 C++ 的知识基本上是不存在的。 我目前正在使用 GATE 模拟 CT 扫描仪,我需要将输出转换为 bmp 文件。 Gate 制作了一系列
link 在 chrome 中,它运行完美。但是,在 Firefox 中,图像不会出现。 我已经设置了 SVG 的 mime 类型,并且 mime 类型检查器显示 mime 类型是正确的。 有人能帮帮
我是一名优秀的程序员,十分优秀!