def test_init(self): unet_config = UnetConfig(input_size=(16, 16, 3), filters=10, dropout=0.6, batchnorm=False) unet = Unet(config=unet_config) unet.compile(loss="binary_crossentropy", metrics=["accuracy"]) unet.summary()
import cv2 from models.unet import Unet from data_augmentation.data_augmentation import DataAugmentation import numpy as np gpus = tf.config.experimental.list_physical_devices('GPU') tf.config.experimental.set_memory_growth(gpus[0], True) # Initialize IMAGE_PATH = "dataset/Original/Testing/" MASK_PATH = "dataset/MASKS/Testing/" IMAGE_FILE = "Frame00314-org" model = Unet(input_shape=(224, 224, 1)).build() model.load_weights("models/model_weight.h5") model.summary() print("yeah") def convert_to_tensor(numpy_image): numpy_image = np.expand_dims(numpy_image, axis=2) numpy_image = np.expand_dims(numpy_image, axis=0) tensor_image = tf.convert_to_tensor(numpy_image) return tensor_image def predict(image): process_obj = DataAugmentation(input_size=224, output_size=224) image_processed = process_obj.data_process_test(image) tensor_image = convert_to_tensor(image_processed) predicted_mask = model.predict(tensor_image)
def test_default_init(self): unet = Unet() unet.compile() unet.summary()
def lr_scheduler(epoch): lr = learning_rate new_lr = lr * 0.1**(epoch // 10) return max(new_lr, 1e-10) with tf.device('/device:GPU:0'): unet = Unet().build(IMAGE_SHAPE) model_json = unet.to_json() with open(os.path.join(SEGMENT_RESULT_PATH, 'model.json'), 'w') as f: f.write(json.dumps(model_json)) unet.compile(loss=loss_func, optimizer=optim, metrics=[monitors]) unet.summary() # with open(os.path.join(SEGMENT_RESULT_PATH,'model.json'), 'r') as f: # model_json = json.loads(f.read()) # unet = keras.models.model_from_json(model_json) augm = { "gamma": True, "rotate": True, "flip": True, "hiseq": False, "normal": False, "invert": False, "crop": True }