microsoftml.resize_image: 이미지 크기 조정

Usage

microsoftml.resize_image(cols: [str, dict, list], width: int = 224,
    height: int = 224, resizing_option: ['IsoPad', 'IsoCrop',
    'Aniso'] = 'IsoCrop', **kargs)

설명

지정된 크기 조절 방법을 사용하여 이미지를 지정된 크기로 크기 조정합니다.

세부 정보

resize_image 지정된 크기 조절 방법을 사용하여 이미지를 지정된 높이와 너비로 크기 조정합니다. 이 변환의 입력 변수는 이미지여야 하며, 일반적으로 변환의 load_image 결과입니다.

Arguments

cols

변환할 변수 이름 문자열 또는 목록입니다. 만약 이면 dict, 키는 새로 생성할 변수들의 이름을 나타냅니다.

width

픽셀 단위로 축소된 이미지의 너비를 지정합니다. 기본 숫자는 224입니다.

높이

축소된 이미지의 높이를 픽셀 단위로 지정합니다. 기본 숫자는 224입니다.

resizing_option

사용할 크기 조절 방법을 지정했습니다. 모든 방법이 쌍선형 보간을 사용하고 있다는 점에 유의하세요. 옵션은 다음과 같습니다.

  • "IsoPad": 화면비가 유지되도록 이미지를 재조정합니다. 필요하다면 이미지에 검은색을 덧칠해 새로운 너비나 높이에 맞게 덧칠합니다.

  • "IsoCrop": 화면비가 유지되도록 이미지를 재조정합니다. 필요하다면 이미지를 새로운 너비나 높이에 맞게 잘라냅니다.

  • "Aniso": 이미지는 화면비를 유지하지 않고 새로운 너비와 높이로 늘어납니다.

기본값은 "IsoPad"입니다.

kargs

컴퓨팅 엔진으로 전송된 추가 인수입니다.

Returns

변환을 정의하는 개체입니다.

Example

'''
Example with images.
'''
import numpy
import pandas
from microsoftml import rx_neural_network, rx_predict, rx_fast_linear
from microsoftml import load_image, resize_image, extract_pixels
from microsoftml.datasets.image import get_RevolutionAnalyticslogo

train = pandas.DataFrame(data=dict(Path=[get_RevolutionAnalyticslogo()], Label=[True]))

# Loads the images from variable Path, resizes the images to 1x1 pixels
# and trains a neural net.
model1 = rx_neural_network("Label ~ Features", data=train, 
            ml_transforms=[            
                    load_image(cols=dict(Features="Path")), 
                    resize_image(cols="Features", width=1, height=1, resizing="Aniso"), 
                    extract_pixels(cols="Features")], 
            ml_transform_vars=["Path"], 
            num_hidden_nodes=1, num_iterations=1)

# Featurizes the images from variable Path using the default model, and trains a linear model on the result.
# If dnnModel == "AlexNet", the image has to be resized to 227x227.
model2 = rx_fast_linear("Label ~ Features ", data=train, 
            ml_transforms=[            
                    load_image(cols=dict(Features="Path")), 
                    resize_image(cols="Features", width=224, height=224), 
                    extract_pixels(cols="Features")], 
            ml_transform_vars=["Path"], max_iterations=1)

# We predict even if it does not make too much sense on this single image.
print("\nrx_neural_network")
prediction1 = rx_predict(model1, data=train)
print(prediction1)

print("\nrx_fast_linear")
prediction2 = rx_predict(model2, data=train)
print(prediction2)

Output:

Automatically adding a MinMax normalization transform, use 'norm=Warn' or 'norm=No' to turn this behavior off.
Beginning processing data.
Rows Read: 1, Read Time: 0, Transform Time: 0
Beginning processing data.
Beginning processing data.
Rows Read: 1, Read Time: 0, Transform Time: 0
Beginning processing data.
Beginning processing data.
Rows Read: 1, Read Time: 0.001, Transform Time: 0
Beginning processing data.
Using: AVX Math

***** Net definition *****
  input Data [3];
  hidden H [1] sigmoid { // Depth 1
    from Data all;
  }
  output Result [1] sigmoid { // Depth 0
    from H all;
  }
***** End net definition *****
Input count: 3
Output count: 1
Output Function: Sigmoid
Loss Function: LogLoss
PreTrainer: NoPreTrainer
___________________________________________________________________
Starting training...
Learning rate: 0.001000
Momentum: 0.000000
InitWtsDiameter: 0.100000
___________________________________________________________________
Initializing 1 Hidden Layers, 6 Weights...
Estimated Pre-training MeanError = 0.707823
Iter:1/1, MeanErr=0.707823(0.00%), 0.01M WeightUpdates/sec
Done!
Estimated Post-training MeanError = 0.707499
___________________________________________________________________
Not training a calibrator because it is not needed.
Elapsed time: 00:00:00.0820600
Elapsed time: 00:00:00.0090292
Automatically adding a MinMax normalization transform, use 'norm=Warn' or 'norm=No' to turn this behavior off.
Beginning processing data.
Rows Read: 1, Read Time: 0, Transform Time: 0
Beginning processing data.
Beginning processing data.
Rows Read: 1, Read Time: 0, Transform Time: 0
Beginning processing data.
Beginning processing data.
Rows Read: 1, Read Time: 0, Transform Time: 0
Beginning processing data.
Using 2 threads to train.
Automatically choosing a check frequency of 2.
Auto-tuning parameters: L2 = 5.
Auto-tuning parameters: L1Threshold (L1/L2) = 1.
Using model from last iteration.
Not training a calibrator because it is not needed.
Elapsed time: 00:00:01.0852660
Elapsed time: 00:00:00.0132126

rx_neural_network
Beginning processing data.
Rows Read: 1, Read Time: 0, Transform Time: 0
Beginning processing data.
Elapsed time: 00:00:00.0441601
Finished writing 1 rows.
Writing completed.
  PredictedLabel     Score  Probability
0          False -0.028504     0.492875

rx_fast_linear
Beginning processing data.
Rows Read: 1, Read Time: 0.001, Transform Time: 0
Beginning processing data.
Elapsed time: 00:00:00.5196788
Finished writing 1 rows.
Writing completed.
  PredictedLabel  Score  Probability
0          False    0.0          0.5