- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试训练 resnet50 模型来解决图像分类问题。在我拥有的图像数据集上训练模型之前,我已经加载了“imagenet”预训练权重。我正在使用 keras 函数 flow_from_directory() 从目录加载图像。
train_datagen = ImageDataGenerator()
train_generator = train_datagen.flow_from_directory(
'./train_qcut_2_classes',
batch_size=batch_size,
shuffle=True,
target_size=input_size[1:],
class_mode='categorical')
test_datagen = ImageDataGenerator()
validation_generator = test_datagen.flow_from_directory(
'./validate_qcut_2_classes',
batch_size=batch_size,
target_size=input_size[1:],
shuffle=True,
class_mode='categorical')
我将生成器作为参数传递到 fit_generator 函数中。
hist2=model.fit_generator(train_generator,
samples_per_epoch=102204,
validation_data=validation_generator,
nb_val_samples=25547,
nb_epoch=80, callbacks=callbacks,
verbose=1)
问题:
通过此设置,如何使用 preprocess_input() 函数在将输入图像传递给模型之前对其进行预处理?
from keras.applications.resnet50 import preprocess_input
我尝试使用如下的 preprocessing_function 参数
train_datagen=ImageDataGenerator(preprocessing_function=preprocess_input)
train_generator = train_datagen.flow_from_directory(
'./train_qcut_2_classes',
batch_size=batch_size,
shuffle=True,
target_size=input_size[1:],
class_mode='categorical')
test_datagen = ImageDataGenerator(preprocessing_function=preprocess_input)
validation_generator = test_datagen.flow_from_directory(
'./validate_qcut_2_classes',
batch_size=batch_size,
target_size=input_size[1:],
shuffle=True,
class_mode='categorical')
当我尝试提取预处理输出时,我得到了以下结果。
train_generator.next()[0][0]
array([[[ 91.06099701, 80.06099701, 96.06099701, ..., 86.06099701,
52.06099701, 12.06099701],
[ 101.06099701, 104.06099701, 118.06099701, ..., 101.06099701,
63.06099701, 19.06099701],
[ 117.06099701, 103.06099701, 88.06099701, ..., 88.06099701,
74.06099701, 18.06099701],
...,
[-103.93900299, -103.93900299, -103.93900299, ..., -24.93900299,
-38.93900299, -24.93900299],
[-103.93900299, -103.93900299, -103.93900299, ..., -52.93900299,
-27.93900299, -39.93900299],
[-103.93900299, -103.93900299, -103.93900299, ..., -45.93900299,
-29.93900299, -28.93900299]],
[[ 81.22100067, 70.22100067, 86.22100067, ..., 69.22100067,
37.22100067, -0.77899933],
[ 91.22100067, 94.22100067, 108.22100067, ..., 86.22100067,
50.22100067, 6.22100067],
[ 107.22100067, 93.22100067, 78.22100067, ..., 73.22100067,
62.22100067, 6.22100067],
...,
[-116.77899933, -116.77899933, -116.77899933, ..., -36.77899933,
-50.77899933, -36.77899933],
[-116.77899933, -116.77899933, -116.77899933, ..., -64.77899933,
-39.77899933, -51.77899933],
[-116.77899933, -116.77899933, -116.77899933, ..., -57.77899933,
-41.77899933, -40.77899933]],
[[ 78.31999969, 67.31999969, 83.31999969, ..., 61.31999969,
29.31999969, -7.68000031],
[ 88.31999969, 91.31999969, 105.31999969, ..., 79.31999969,
43.31999969, -0.68000031],
[ 104.31999969, 90.31999969, 75.31999969, ..., 66.31999969,
53.31999969, -2.68000031],
...,
[-123.68000031, -123.68000031, -123.68000031, ..., -39.68000031,
-53.68000031, -39.68000031],
[-123.68000031, -123.68000031, -123.68000031, ..., -67.68000031,
-42.68000031, -54.68000031],
[-123.68000031, -123.68000031, -123.68000031, ..., -60.68000031,
-44.68000031, -43.68000031]]], dtype=float32)
为了证实这一点,我直接对特定图像使用了预处理函数,
import cv2
img = cv2.imread('./images.jpg')
img = img_to_array(img)
x = np.expand_dims(img, axis=0)
x = x.astype(np.float64)
x = preprocess_input(x)
给出以下输出,
array([[[[ 118.061, 125.061, 134.061, ..., 97.061, 99.061, 102.061],
[ 118.061, 125.061, 133.061, ..., 98.061, 100.061, 102.061],
[ 113.061, 119.061, 126.061, ..., 100.061, 101.061, 102.061],
...,
[ 65.061, 64.061, 64.061, ..., 60.061, 61.061, 57.061],
[ 64.061, 64.061, 63.061, ..., 66.061, 67.061, 59.061],
[ 56.061, 59.061, 62.061, ..., 61.061, 60.061, 59.061]],
[[ 113.221, 120.221, 129.221, ..., 112.221, 114.221, 113.221],
[ 116.221, 123.221, 131.221, ..., 113.221, 115.221, 113.221],
[ 118.221, 124.221, 131.221, ..., 115.221, 116.221, 113.221],
...,
[ 56.221, 55.221, 55.221, ..., 51.221, 52.221, 51.221],
[ 55.221, 55.221, 54.221, ..., 57.221, 58.221, 53.221],
[ 47.221, 50.221, 53.221, ..., 52.221, 51.221, 50.221]],
[[ 109.32 , 116.32 , 125.32 , ..., 106.32 , 108.32 , 108.32 ],
[ 111.32 , 118.32 , 126.32 , ..., 107.32 , 109.32 , 108.32 ],
[ 111.32 , 117.32 , 124.32 , ..., 109.32 , 110.32 , 108.32 ],
...,
[ 34.32 , 33.32 , 33.32 , ..., 30.32 , 31.32 , 26.32 ],
[ 33.32 , 33.32 , 32.32 , ..., 36.32 , 37.32 , 28.32 ],
[ 25.32 , 28.32 , 31.32 , ..., 30.32 , 29.32 , 28.32 ]]]])
关于为什么会发生这种情况有什么想法吗?
最佳答案
作为创建ImageDataGenerator
时的参数:
train_datagen = ImageDataGenerator(preprocessing_function=preprocess_input)
关于python - 预处理使用 keras 函数 ImageDataGenerator() 生成的图像来训练 resnet50 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50133385/
当我同时定义两条指令时,如何做到这一点,我会收到编译错误? 在这里我想要错误 #define ENG #define POL #if defined POL #if defined ENG 这里没有
我有actix-web,并且调试困难,因为记录器仅在最后写入,如果出现故障,则根本不会写入。RUST_LOG=actix_web=debug,actix_server=debug let server
对于以下有关数据预处理聚类的问题,我很困惑,在互联网上找不到令人信服的答案。 根据Python documentation ,当我们使用 sckit learn 库中的内置命令进行预处理时,假设数据被
我无法理解预处理器的工作原理以及 ## 在这个特定示例中代表什么 #include #define TEMP_KEY(type,Key) (TEMP_##type | Key) enum TEMPK
我一直在尝试对 Kaggle 上的 Sentiment140 数据库进行一些预处理:https://www.kaggle.com/kazanova/sentiment140 我使用的代码是这样的: i
例如,考虑在 Keras 中微调 Resnet50 模型。 For example here : from keras.applications.resnet50 import ResNet50 fr
我想预处理 JavaScript 属性名称以将其转换为 { 'extension': object, 'config': {id: 1} } 到 { extension: object,
我在编译 C 程序时在预处理步骤中遇到错误。 奇怪的是,我可以运行预处理而没有错误或警告: gcc -I/usr/local/libpng-1.6.24/include -Wall -std=c99
我很好奇 GCC 预处理步骤的输出。更准确地说,以下两行的目的是什么: # 1 "" # 1 "" 我知道格式是 但我不明白本节中可能会出现什么类型的数据。它的目的是什么? 谢谢! 最佳答案 目的是
我需要能够预处理多个 C# 文件作为项目的预构建步骤,检测方法的开始,并在方法开始处插入生成的代码,在任何现有代码之前。但是,我在检测方法的打开时遇到问题。我最初尝试了一个正则表达式来匹配,但最终出现
如何使用 C 预处理自动生成以下代码模式(访问器)? // Immutable accessor. const auto& member1 () const { return _member1;
我正在考虑分两个阶段实现 C 预处理器,其中第一阶段将源文件转换为预处理标记数组。这对于简单性和性能都有好处,因为当项目中的多个文件包含头文件时,不需要重做标记化工作。 障碍: #define f(x
有没有办法“预处理”C99 样式的二合字母以获得 C 文件(或 .i 预处理源),使得生成的文件不包含任何二合字母? 例如,给出以下源代码: %:define N 5 int main() = ;
如何使用 browserify 预处理函数调用? 在一个大的 js 文件中,有时我需要将一个 JSON 对象传递给一个变量,但这个 JSON 对象只能通过函数调用创建: var myvar = Rac
我正在对电视镜头中的字幕应用 OCR。 (我正在使用带 C++ 的 Tesseact 3.x)我正在尝试拆分文本和背景部分作为 OCR 的预处理。 这是原图: 然后,预处理图像: OCR结果为:Sic
我正在开发一个函数,该函数采用众所周知的参数范围,但我不想为每种情况编写许多不同的函数。有没有一种方法可以定义函数的“模式”并使预编译器根据这种模式生成函数? 例子。我有以下功能: int addit
我有一个包含多个脚本标签(接近 20 个)的 html 文件。我决定将所有 JS 文件连接成一个文件,然后缩小连接后的文件。我正在使用 ant 任务来连接并将这样做以进行缩小。我知道我需要提供非串联/
我想在 AngularJS 更新任何 HTML 之前添加一个预处理步骤。为了简单起见,让我们将 hello 的所有实例都加粗。 . 也就是说,如果我们让$scope.text = "hello wor
我正在使用 tess4j 作为来自 JAVA 的 tesseract 的包装器对图像运行一系列 OCR。 ocr 的过程仍然需要大量时间(有时甚至 5 秒),我正在努力加快它的速度。 我正在对图像进行
我一直在阅读有关 Phing 和 Ant 的文章,但我不确定这些工具中哪一个(如果有的话)对这种情况最有用。 它很容易是调试语句等,但我会给你我们的字面扫描。 我们有一个可下载的 PHP 应用程序的免
我是一名优秀的程序员,十分优秀!