- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Python 和 Keras 进行深度学习的图像色彩校正的监督方法。我完成了数据训练并预测了测试数据的值。现在,我想显示数据集中的一些颜色校正图像,以便我可以将它们与原始图像进行视觉比较。我陷入了循环,我不知道如何解决这。有人可以帮助我编写代码或一些提示吗?
我已经比较了预测照明和地面真实照明的数量,但我想绘制它们在预测照明下的外观图片。我正在使用三倍交叉验证,这使得它变得更加困难。我有 1000 多张图像,但为了简单起见,我们假设只有 12 张。我将训练其中 8 个并测试其中 4 个。
#this is the part where the training and testing is happening, images are loaded
#in xs variable and ground truth illumination is loaded in ys variable
for i in range (3):
print('\nFold ',i)
X_train = xs [folds[i]==0, :]
X_test = xs [folds[i]==1, :]
Y_train = ys [folds[i]==0, :]
Y_test = np.zeros((4,3), dtype=np.uint8)
model = None
model = create_model()
history = model.fit(X_train, Y_train, epochs=10, batch_size=8)
Y_test = model.predict(X_test, batch_size=4)
print("Predicted values for fold %d:" % i, Y_test)
for y in Y_test[:]:
predicted.append(y)
这部分代码运行完美,我不知道的是如何在使用预测照明进行颜色校正后绘制甚至保存这 12 个图像中的每一个。
编辑:我已经提取了每张照片的预测值。如何将它们应用到图像上?
最佳答案
如果我理解正确的话,您希望使用模型预测的光源对偏色图像进行白平衡。您的预测由 3 个值(比方说 [alpha、beta、ceta])组成,它们是将应用于色偏图像的每个 channel (蓝色、绿色、红色)的校正增益。
但是,在应用校正增益之前,您需要对图像执行 Gamma 线性化(更多信息请参见here)。
这里有一些示例代码可以帮助您:
import cv2
import numpy as np
def gamma_decode(B_gamma, G_gamma, R_gamma):
B_gamma = B_gamma/255
G_gamma = G_gamma/255
R_gamma = R_gamma/255
gamma = 1/2.2
B_gamma_decode = 255*(B_gamma**(1/gamma))
G_gamma_decode = 255*(G_gamma**(1/gamma))
R_gamma_decode = 255*(R_gamma**(1/gamma))
return (B_gamma_decode, G_gamma_decode, R_gamma_decode)
def gamma_encode(B_channel, G_channel, R_channel):
B_channel = B_channel/255
G_channel = G_channel/255
R_channel = R_channel/255
gamma = 1/2.2
if np.all(B_channel <= 0):
B_gamma_cor = (B_channel**(gamma + 0j))
B_gamma_cor = 255*(abs(B_gamma_cor))
else:
B_gamma_cor = 255*(B_channel**gamma)
if np.all(G_channel <= 0):
G_gamma_cor = (G_channel**(gamma + 0j))
G_gamma_cor = 255*(abs(G_gamma_cor))
else:
G_gamma_cor = 255*(G_channel**gamma)
if np.all(R_channel <= 0):
R_gamma_cor = (R_channel**(gamma + 0j))
R_gamma_cor = 255*(abs(R_gamma_cor))
else:
R_gamma_cor = 255*(R_channel**gamma)
return (B_gamma_cor, G_gamma_cor, R_gamma_cor)
def white_balance(img, pred_illum)
B_channel, G_channel, R_channel = cv2.split(img)
alpha, beta, ceta = pred_illum
#Gamma_decoding
B_channel, G_channel, R_channel = gamma_decode(B_channel, G_channel, R_channel)
#Correction
B_cor = (alpha*B_channel)
G_cor = (beta*G_channel)
R_cor = (ceta*R_channel)
#Gamma encoding
B_cor, G_cor, R_cor = gamma_encode(B_cor, G_cor, R_cor)
#Convert to uint8 to display
B_cor = B_cor.astype(np.uint8)
G_cor = G_cor.astype(np.uint8)
R_cor = R_cor.astype(np.uint8)
img_white_balanced = cv2.merge((B_cor, G_cor, R_cor))
return img_white_balanced
关于python - 如何在Python和Keras中通过深度学习进行光照估计后显示颜色校正图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56396730/
我有兴趣在 tf.keras 中训练一个模型,然后用 keras 加载它。我知道这不是高度建议,但我对使用 tf.keras 来训练模型很感兴趣,因为 tf.keras 更容易构建输入管道 我想利用
我进行了大量搜索,但仍然无法弄清楚如何编写具有多个交互输出的自定义损失函数。 我有一个神经网络定义为: def NeuralNetwork(): inLayer = Input((2,));
我正在阅读一篇名为 Differential Learning Rates 的文章在 Medium 上,想知道这是否可以应用于 Keras。我能够找到在 pytorch 中实现的这项技术。这可以在 K
我正在实现一个神经网络分类器,以打印我正在使用的这个神经网络的损失和准确性: score = model.evaluate(x_test, y_test, verbose=False) model.m
我最近在查看模型摘要时遇到了这个问题。 我想知道,[(None, 16)] 和有什么区别?和 (None, 16) ?为什么输入层有这样的输入形状? 来源:model.summary() can't
我正在尝试使用 Keras 创建自定义损失函数。我想根据输入计算损失函数并预测神经网络的输出。 我尝试在 Keras 中使用 customloss 函数。我认为 y_true 是我们为训练提供的输出,
我有一组样本,每个样本都是一组属性的序列(例如,一个样本可以包含 10 个序列,每个序列具有 5 个属性)。属性的数量总是固定的,但序列的数量(时间戳)可能因样本而异。我想使用这个样本集在 Keras
Keras 在训练集和测试集文件夹中发现了错误数量的类。我有 3 节课,但它一直说有 4 节课。有人可以帮我吗? 这里的代码: cnn = Sequential() cnn.add(Conv2D(32
我想编写一个自定义层,在其中我可以在两次运行之间将变量保存在内存中。例如, class MyLayer(Layer): def __init__(self, out_dim = 51, **kwarg
我添加了一个回调来降低学习速度: keras.callbacks.ReduceLROnPlateau(monitor='val_loss', factor=0.5, patience=100,
在 https://keras.io/layers/recurrent/我看到 LSTM 层有一个 kernel和一个 recurrent_kernel .它们的含义是什么?根据我的理解,我们需要 L
问题与标题相同。 我不想打开 Python,而是使用 MacOS 或 Ubuntu。 最佳答案 Python 库作者将版本号放入 .__version__ 。您可以通过在命令行上运行以下命令来打印它:
Keras 文档并不清楚这实际上是什么。我知道我们可以用它来将输入特征空间压缩成更小的空间。但从神经设计的角度来看,这是如何完成的呢?它是一个自动编码器,RBM吗? 最佳答案 据我所知,嵌入层是一个简
我想实现[http://ydwen.github.io/papers/WenECCV16.pdf]中解释的中心损失]在喀拉斯 我开始创建一个具有 2 个输出的网络,例如: inputs = Input
我正在尝试实现多对一模型,其中输入是大小为 的词向量d .我需要输出一个大小为 的向量d 在 LSTM 结束时。 在此 question ,提到使用(对于多对一模型) model = Sequenti
我有不平衡的训练数据集,这就是我构建自定义加权分类交叉熵损失函数的原因。但问题是我的验证集是平衡的,我想使用常规的分类交叉熵损失。那么我可以在 Keras 中为验证集传递不同的损失函数吗?我的意思是用
DL 中的一项常见任务是将输入样本归一化为零均值和单位方差。可以使用如下代码“手动”执行规范化: mean = np.mean(X, axis = 0) std = np.std(X, axis =
我正在尝试学习 Keras 并使用 LSTM 解决分类问题。我希望能够绘制 准确率和损失,并在训练期间更新图。为此,我正在使用 callback function . 由于某种原因,我在回调中收到的准
在 Keras 内置函数中嵌入使用哪种算法?Word2vec?手套?其他? https://keras.io/layers/embeddings/ 最佳答案 简短的回答是都不是。本质上,GloVe 的
我有一个使用 Keras 完全实现的 LSTM RNN,我想使用梯度剪裁,梯度范数限制为 5(我正在尝试复制一篇研究论文)。在实现神经网络方面,我是一个初学者,我将如何实现? 是否只是(我正在使用 r
我是一名优秀的程序员,十分优秀!