resizeImage:機器學習調整影像大小轉換

使用指定的調整大小方法,將影像大小調整成指定的維度。

使用方式

  resizeImage(vars, width = 224, height = 224, resizingOption = "IsoCrop")

引數

vars

輸入變數名稱和輸出變數名稱的字元向量具名清單。 請注意,輸入變數必須為相同類型。 對於輸入與輸出變數之間的一對一對應,可以使用具名字元向量。

width

指定縮放影像的寬度 (以像素為單位)。 預設值為 224。

height

指定縮放影像的高度 (以像素為單位)。 預設值為 224。

resizingOption

指定要使用的調整大小方法。 請注意,所有方法都使用雙線性插補。 選項包括:

  • "IsoPad":影像會調整大小以保留外觀比例。 如有需要,可用黑色填補影像,以因應新的寬度或高度。
  • "IsoCrop":影像會調整大小以保留外觀比例。 如有需要,可裁切影像以因應新的寬度或高度。
  • "Aniso":影像會延展到新的寬度和高度,而不會保留外觀比例。 預設值是 "IsoPad"

詳細資料

resizeImage 會使用指定的調整大小方法,將影像大小調整為指定的高度和寬度。 此轉換的輸入變數必須是影像,通常是 loadImage 轉換的結果。

定義轉換的 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")