Exemple #1
0
    """
    
    _transform = [
        A.Lambda(image=preprocessing_fn),
    ]
    return A.Compose(_transform)


# BACKBONE = 'efficientnetb3'
BACKBONE = args.backbone
BATCH_SIZE = args.batch_size
CLASSES = ['live', 'inter', 'dead']
LR = args.lr
EPOCHS = args.epoch

preprocess_input = sm.get_preprocessing(BACKBONE)

# define network parameters
n_classes = 1 if len(CLASSES) == 1 else (len(CLASSES) + 1)  # case for binary and multiclass segmentation
activation = 'sigmoid' if n_classes == 1 else 'softmax'

#create model
net_func = globals()[args.net_type]

encoder_weights='imagenet' if args.pre_train else None

if not args.net_type=='PSPNet':
    model = net_func(BACKBONE, encoder_weights=encoder_weights, classes=n_classes, activation=activation,\
    		decoder_block_type = args.upsample,\
    		decoder_filters=(int(args.filters),int(args.filters/2), int(args.filters/4), int(args.filters/8), int(args.filters/16)))
    print('{}'.format((int(args.filters),int(args.filters/2), int(args.filters/4), int(args.filters/8), int(args.filters/16))))
Exemple #2
0

# network
if not best_flag:
    model_file = model_folder + '/best_model-{:03d}.h5'.format(epoch)
    print(os.path.exists(model_file))
    if os.path.exists(model_file):
        best_weight = model_file
    else:
        best_weight = model_folder + '/best_model.h5'
else:
    best_weight = model_folder + '/weights_{:02d}.h5'.format(
        epoch) if epoch < 100 else model_folder + '/weights_{:03d}.h5'.format(
            epoch)

preprocess_input = sm.get_preprocessing(backbone)

#create model
n_classes = cho if not fl_ch == 'fl12' else 2
activation = 'relu'
net_func = globals()[net_arch]
model = net_func(backbone,
                 classes=n_classes,
                 encoder_weights=None,
                 activation=activation)

#load best weights
model.load_weights(best_weight)

## save model
model.save(model_folder + '/ready_model.h5')