Проблема типа данных с классом Imagedatagenerator и настройкой preprocessing_function - PullRequest
0 голосов
/ 21 апреля 2020

Как часть учебного сценария CNN с TF Keras, я хочу применить пользовательскую функцию предварительной обработки, используя класс Keras'ImageDataGenerator. После создания 2 экземпляров типа ImageDataGenerator, в котором я использую эту пользовательскую функцию предварительной обработки под названием «N4»; через параметр для передачи во время создания экземпляра:

'' '

  # data Augmentation
train_datagen = ImageDataGenerator(
    #preprocessing_function=preprocess_input,
    preprocessing_function=N4, # CLAHE_fct # preprocess_input,
    width_shift_range=0.4,
            shear_range=0.2,# dans train-ai.py shear_range=0.4,
    zoom_range=0.1,# dans train-ai.py zoom_range=0.4
    #rotation_range=random.randrange(-25, 25, 2),# dans train-ai.py pas de rotation_range
    horizontal_flip=True,
    vertical_flip=True
)

# data Augmentation
valid_datagen = ImageDataGenerator(
    #preprocessing_function=preprocess_input,
    preprocessing_function=N4, #CLAHE_fct # preprocess_input,
    width_shift_range=0.4,
    shear_range=0.2,# dans train-ai.py shear_range=0.4,
    zoom_range=0.1,# dans train-ai.py zoom_range=0.4
    #rotation_range=random.randrange(-25, 25, 2),# dans train-ai.py pas de rotation_range
    horizontal_flip=True,
    vertical_flip=True
)

' ''

пользовательская функция предварительной обработки выглядит следующим образом:

' ''

 def N4(img):
    print("N4 bias correction runs.")
    inputImage = img
    print("Affectation & affichage du type de img au sortir de ImageDataGenerator et en entrée de la fonction N4 : ")
    imgType = img.dtype
    print("img est de Type : ")
    print(imgType)
    my_inputImage_float32 = img
    my_inputImage_unint8 = tf.cast(my_inputImage_float32, dtype=tf.uint8)
    print("Affectation & affichage du type de my_inputImage_unint8 avant d_etre traitee par la fonction N4 : ")
    my_inputImage_unint8Type = my_inputImage_unint8.dtype
    print("my_inputImage_unint8 est de Type : ")
    print(my_inputImage_unint8Type)
    maskImage = sitk.OtsuThreshold(my_inputImage_unint8, 0, 1, 200)
    """sitk.WriteImage(maskImage,
                    "20160129-pt-3f9fed2f1c-std-cdf25fa63a-seq-1-ang-p31.4-p15.3-f-00084_mask3_N4_bias_corrected.png")"""
    my_inputImage_unint8 = sitk.Cast(inputImage, sitk.sitkFloat32)  # Float32 car sinon fct n'accepte pas

    corrector = sitk.N4BiasFieldCorrectionImageFilter()

    N4_output = corrector.Execute(my_inputImage_unint8, maskImage)
    N4_output = sitk.Cast(N4_output, sitk.sitkUInt8)  # ajoute pour sauver en .PNG
    N4_output_float32 = np.float32(output)  # Convert image from unsigned 8 bit to 32 bit float
    print("Affectation & affichage du type de N4_output_float32 avant d_etre retourne par la fonction CLAHE et de rentrer dans ImageDataGenerator : ")
    N4_output_float32Type = N4_output_float32.dtype
    print("N4_output_float est de Type : ")
    print(N4_output_floatType)
    return N4_output_float32
    print("Finished N4 Bias Field Correction.....")

'' '

вот возвращенное сообщение об ошибке:

' '' 'Файл' C: \ Users \ QTR7701 \ AppData \ Roaming \ Python \ Python37 \ site-packages \ SimpleITK \ SimpleITK.py ", строка 54421, в OtsuThreshold возвращает _SimpleITK.OtsuThreshold (* args) NotImplementedError: неверный номер или тип аргументов для перегруженной функции 'OtsuThreshold'. Возможные прототипы C / C ++: itk :: simple :: OtsuThreshold (itk :: simple :: Изображение const &, itk :: simple :: Image const &, uint8_t, uint8_t, uint32_t, bool, uint8_t) itk :: simple: : OtsuThreshold (itk :: simple :: Image const &, uint8_t, uint8_t, uint32_t, bool, uint8_t) '' '

Несмотря на выполнение преобразований типов данных в функции N4

  • тип изображения для функции предварительной обработки N4 представляет собой 8 бит без знака
  • Список типов изображений, прошедших функцию предварительной обработки ImageDataGenerator: Integer float32

Не могу найти решение для это сообщение об ошибке. Кто-нибудь может мне помочь?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...