Пример #1
0
    def test_unet_model(self):
        image = Raster \
            .read \
            .format("geotiff") \
            .load(TEST_IMAGE_PATH)

        label: Raster = Raster \
            .read \
            .format("shp") \
            .options(
            pixel=image.pixel,
            extent=image.extent
        ) \
            .load(self.shape_path)

        standarize1 = ImageStand(raster=image)
        standarized = standarize1.standarize_image(StandardScaler())
        raster_data = RasterData(standarized, label)
        unet_images = raster_data.prepare_unet_data(image_size=[64, 64])

        callbacks = [
            EarlyStopping(patience=100, verbose=1),
            ReduceLROnPlateau(factor=0.1, patience=100, min_lr=0, verbose=1),
            ModelCheckpoint('model_more_class_pixels.h5',
                            verbose=1,
                            save_best_only=True,
                            save_weights_only=False)
        ]
        config = UnetConfig(
            input_size=[64, 64, 3],
            metrics=["accuracy"],
            optimizer=SGD(lr=0.001),
            callbacks=callbacks,
            loss="binary_crossentropy",
        )
        #
        unet = Unet(config=config)
        unet.compile()
        unet.fit(unet_images, epochs=1)
        predicted = unet.predict(x=unet_images.x_test[0], threshold=0.4)
        SubPlots().extend(predicted, unet_images.x_test[0]).plot(nrows=1)
Пример #2
0
import nibabel as nib
from PIL import Image

from utils import dice_coef_loss, dice_coef, one_hot_encode, standardize

#checkpoint = ModelCheckpoint('new/weights.h5', monitor='val_loss', verbose=1, save_best_only=True, mode='min')
#earlystopping = EarlyStopping(monitor = 'val_loss', verbose = 1,min_delta = 0.01, patience = 3, mode = 'min')
#callbacks_list = [checkpoint, earlystopping]

input_img = Input((240, 240, 4))
model = Unet(input_img, 16, 0.1, True)
learning_rate = 0.001
epochs = 5000
decay_rate = learning_rate / epochs
model.compile(optimizer=Adam(lr=learning_rate, decay=decay_rate),
              loss=dice_coef_loss,
              metrics=[dice_coef])
model.summary()

# data preprocessing starts here
path = '../BRATS2017/Brats17TrainingData/HGG'
all_images = os.listdir(path)
#print(len(all_images))
all_images.sort()
data = np.zeros((240, 240, 155, 4))
x_to = []
y_to = []

for i in range(1):
    print(i)
Пример #3
0
os.environ["CUDA_VISIBLE_DEVICES"] = "0, 1"

tfconfig = tf.ConfigProto()
tfconfig.gpu_options.allow_growth = True
tfconfig.allow_soft_placement = True
sess = tf.Session(config=tfconfig)
sess.run(tf.compat.v1.global_variables_initializer())
keras.backend.set_session(sess)

input_img = Input((512, 512, 3))
model = Unet(input_img, 16, 0.1, True)
learning_rate = 0.001
epochs = 500
decay_rate = learning_rate / epochs
model.compile(optimizer=Adam(lr=learning_rate, decay=decay_rate), loss='mse')
model.summary()

history = model.fit(x=x, y=x, batch_size=32, epochs=20)

maxpool_model = keras.Sequential()
maxpool_model.add(layers.MaxPooling2D(pool_size=(2, 2), strides=2))

flair_encoder = Model(model.input, model.get_layer('activation_10').output)
flair_encoder.summary()

bottleneck = flair_encoder.predict(x)
bottleneck = maxpool_model.predict(bottleneck)
print('Shape of bottleneck: ', bottleneck.shape)
bottleneck = bottleneck.reshape((409, 65536))