从图像中提取像素值。
用法
extractPixels(vars, useAlpha = FALSE, useRed = TRUE, useGreen = TRUE,
useBlue = TRUE, interleaveARGB = FALSE, convert = TRUE, offset = NULL,
scale = NULL)
参数
vars
输入变量名称和输出变量名称的字符向量的命名列表。 请注意,所有输入变量的类型必须相同。 对于输入变量和输出变量之间的一对一映射,可以使用命名字符向量。
useAlpha
指定是否使用 alpha 通道。 默认值是 FALSE。
useRed
指定是否使用红色通道。 默认值是 TRUE。
useGreen
指定是否使用绿色通道。 默认值是 TRUE。
useBlue
指定是否使用蓝色通道。 默认值是 TRUE。
interleaveARGB
是分隔每个通道还是按 ARGB 顺序交错。 例如,如果要训练卷积神经网络,这可能很重要,因为这会影响内核的形状、步幅等。
convert
是否转换为浮点数。 默认值是 FALSE。
offset
指定偏移量(缩放前)。 这需要 convert = TRUE。 默认值是 NULL。
scale
指定缩放系数。 这需要 convert = TRUE。 默认值是 NULL。
详细信息
extractPixels 从图像中提取像素值。 输入变量是大小相同的图像,通常是 resizeImage 转换的输出。 输出是向量形式的像素数据,通常用作学习器的特征。
值
一个 maml 对象,用于定义转换。
作者
Microsoft Corporation Microsoft Technical Support
示例
train <- data.frame(Path = c(system.file("help/figures/RevolutionAnalyticslogo.png", package = "MicrosoftML")), Label = c(TRUE), stringsAsFactors = FALSE)
# Loads the images from variable Path, resizes the images to 1x1 pixels and trains a neural net.
model <- rxNeuralNet(
Label ~ Features,
data = train,
mlTransforms = list(
loadImage(vars = list(Features = "Path")),
resizeImage(vars = "Features", width = 1, height = 1, resizing = "Aniso"),
extractPixels(vars = "Features")
),
mlTransformVars = "Path",
numHiddenNodes = 1,
numIterations = 1)
# Featurizes the images from variable Path using the default model, and trains a linear model on the result.
model <- rxFastLinear(
Label ~ Features,
data = train,
mlTransforms = list(
loadImage(vars = list(Features = "Path")),
resizeImage(vars = "Features", width = 224, height = 224), # If dnnModel == "AlexNet", the image has to be resized to 227x227.
extractPixels(vars = "Features"),
featurizeImage(var = "Features")
),
mlTransformVars = "Path")