def load_model(checkpoint_file):
    checkpoint = torch.load(checkpoint_file)
    args = checkpoint['args']
    model = UnetModel(1, 1, args.num_chans, args.num_pools,
                      args.drop_prob).to(args.device)
    if args.data_parallel:
        model = torch.nn.DataParallel(model)
    model.load_state_dict(checkpoint['model'])
    return model
def load_model(checkpoint_file):
    checkpoint = torch.load(checkpoint_file)
    args = checkpoint['args']
    if args.irim_train:
        model = make_IRIM()
    else:
        model = UnetModel(1, 1, args.num_chans, args.num_pools, args.drop_prob).to(args.device)
    if args.data_parallel:
        model = torch.nn.DataParallel(model)
    print(model.load_state_dict(checkpoint['model']))
    return model
def build_model(args):
    model = UnetModel(in_chans=1,
                      out_chans=1,
                      chans=args.num_chans,
                      num_pool_layers=args.num_pools,
                      drop_prob=args.drop_prob).to(args.device)
    return model
df_image = pd.read_csv('./processed_data/image_file.csv')
df_mask = pd.read_csv('./processed_data/mask_file.csv')

# scaling data
image_array=df_image.values.reshape([len(df_image),128,128,1])/255.
mask_array=df_mask.values.reshape([len(df_image),128,128,1])/255.

# spliting data for train and test
x_train, x_test, y_train, y_test = train_test_split(image_array, mask_array, test_size=0.1)

# define the size of image prepared through preprocessing
row_size = 128
col_size = 128

# calling unet model class
unet = UnetModel(row_size, col_size, 1)

model = unet.small_unet()
model_checkpoint = ModelCheckpoint('unet_bd.hdf5', monitor='loss',verbose=1, save_best_only=True)
# training the model
model.fit(x_train, y_train,  batch_size=64, nb_epoch=10, verbose=1, shuffle=True,
validation_split=0.2, callbacks=[model_checkpoint])

# predicting on test set 
res = model.predict(x_test)


# simplot to view output
%matplotlib
i=2
plt.figure(figsize=(1,3))
Exemple #5
0
# Use the AI4EAppInsights library to send log messages.
log = AI4EAppInsights()

# Use the APIService to executes your functions within a
# logging trace, supports long-running/async functions,
# handles SIGTERM signals from AKS, etc., and handles
# concurrent requests.
with app.app_context():
	ai4e_service = APIService(app, log)

# Load the model
# The model was copied to this location
# when the container was built; see ../Dockerfile
model_path = '/app/pytorch_api/300_net_G.pth'
model = UnetModel()
model.initialize(model_path)


def process_request_data(request):
	return_values = {'image_bytes': None}
	try:
		# Attempt to load the body
		return_values['image_bytes'] = BytesIO(request.data)
	except:
		log.log_error('Unable to load the request data')
	return return_values


# POST, async API endpoint example
@ai4e_service.api_async_func(