コード例 #1
0
def prepareData(images_mask, images_raw):
    inputArray = []
    expectedArray = []
    for file in os.listdir(images_raw):
        testImage = Image.open(images_raw + file)
        testMask = Image.open(images_mask + file.split(".")[0] + ".jpg")

        for augmented in augmentImage(testImage,
                                      "",
                                      applyGrayscale=False,
                                      printGeneratedLists=False):
            image = augmented[1]
            image = padImage(image, (IMG_WIDTH, IMG_HEIGHT))
            inputValue = img_to_array(image)
            inputValue /= 255
            inputArray.append(inputValue)

        for augmentedMask in augmentImage(testMask,
                                          "",
                                          applyGrayscale=False,
                                          isMask=True,
                                          printGeneratedLists=False):
            image = padImage(augmentedMask[1], (IMG_WIDTH, IMG_HEIGHT))
            expectedOutput = img_to_array(image)
            expectedOutput /= 255
            expectedArray.append(expectedOutput)
    inputArray = numpy.array(inputArray)
    expectedArray = numpy.array(expectedArray)
    return expectedArray, inputArray
コード例 #2
0
def predict(imagePath):
    imageList = os.listdir(imagePath)

    for imageName in imageList:
        img_path = imagePath + imageName

        x = image.img_to_array(padImage(image.load_img(img_path), (256, 256)))
        x /= 255
        x = np.expand_dims(x, axis=0)
        predict = model.predict(x)
        predict[0] *= 255
        array_to_img(predict[0]).show()