本文整理汇总了Python中utils.load_images方法的典型用法代码示例。如果您正苦于以下问题:Python utils.load_images方法的具体用法?Python utils.load_images怎么用?Python utils.load_images使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils
的用法示例。
在下文中一共展示了utils.load_images方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inference
# 需要导入模块: import utils [as 别名]
# 或者: from utils import load_images [as 别名]
def inference(parameters, verbose=True):
"""
Function that creates a model, loads the parameters, and makes a prediction
:param parameters: dictionary of parameters
:param verbose: Whether to print predicted probabilities
:return: Predicted probabilities for each class
"""
# resolve device
device = torch.device(
"cuda:{}".format(parameters["gpu_number"]) if parameters["device_type"] == "gpu"
else "cpu"
)
# construct models
model = models.BaselineBreastModel(device, nodropout_probability=1.0, gaussian_noise_std=0.0).to(device)
model.load_state_dict(torch.load(parameters["model_path"]))
# load input images and prepare data
datum_l_cc = utils.load_images(parameters['image_path'], 'L-CC')
datum_r_cc = utils.load_images(parameters['image_path'], 'R-CC')
datum_l_mlo = utils.load_images(parameters['image_path'], 'L-MLO')
datum_r_mlo = utils.load_images(parameters['image_path'], 'R-MLO')
x = {
"L-CC": torch.Tensor(datum_l_cc).permute(0, 3, 1, 2).to(device),
"L-MLO": torch.Tensor(datum_l_mlo).permute(0, 3, 1, 2).to(device),
"R-CC": torch.Tensor(datum_r_cc).permute(0, 3, 1, 2).to(device),
"R-MLO": torch.Tensor(datum_r_mlo).permute(0, 3, 1, 2).to(device),
}
# run prediction
with torch.no_grad():
prediction_birads = model(x).cpu().numpy()
if verbose:
# nicely prints out the predictions
birads0_prob = prediction_birads[0][0]
birads1_prob = prediction_birads[0][1]
birads2_prob = prediction_birads[0][2]
print('BI-RADS prediction:\n' +
'\tBI-RADS 0:\t' + str(birads0_prob) + '\n' +
'\tBI-RADS 1:\t' + str(birads1_prob) + '\n' +
'\tBI-RADS 2:\t' + str(birads2_prob))
return prediction_birads[0]
示例2: inference
# 需要导入模块: import utils [as 别名]
# 或者: from utils import load_images [as 别名]
def inference(parameters, verbose=True):
# resolve device
device = torch.device(
"cuda:{}".format(parameters["gpu_number"]) if parameters["device_type"] == "gpu"
else "cpu"
)
# load input images
datum_l_cc = utils.load_images(parameters['image_path'], 'L-CC')
datum_r_cc = utils.load_images(parameters['image_path'], 'R-CC')
datum_l_mlo = utils.load_images(parameters['image_path'], 'L-MLO')
datum_r_mlo = utils.load_images(parameters['image_path'], 'R-MLO')
# construct models and prepare data
if parameters["model_type"] == 'cnn':
model = models.BaselineBreastModel(device, nodropout_probability=1.0, gaussian_noise_std=0.0).to(device)
model.load_state_dict(torch.load(parameters["model_path"]))
x = {
"L-CC": torch.Tensor(datum_l_cc).permute(0, 3, 1, 2).to(device),
"L-MLO": torch.Tensor(datum_l_mlo).permute(0, 3, 1, 2).to(device),
"R-CC": torch.Tensor(datum_r_cc).permute(0, 3, 1, 2).to(device),
"R-MLO": torch.Tensor(datum_r_mlo).permute(0, 3, 1, 2).to(device),
}
elif parameters["model_type"] == 'histogram':
model = models.BaselineHistogramModel(num_bins=parameters["bins_histogram"]).to(device)
model.load_state_dict(torch.load(parameters["model_path"]))
x = torch.Tensor(utils.histogram_features_generator([
datum_l_cc, datum_r_cc, datum_l_mlo, datum_r_mlo
], parameters)).to(device)
else:
raise RuntimeError(parameters["model_type"])
# run prediction
with torch.no_grad():
prediction_density = model(x).cpu().numpy()
if verbose:
# nicely prints out the predictions
print('Density prediction:\n'
'\tAlmost entirely fatty (0):\t\t\t' + str(prediction_density[0, 0]) + '\n'
'\tScattered areas of fibroglandular density (1):\t' + str(prediction_density[0, 1]) + '\n'
'\tHeterogeneously dense (2):\t\t\t' + str(prediction_density[0, 2]) + '\n'
'\tExtremely dense (3):\t\t\t\t' + str(prediction_density[0, 3]) + '\n')
return prediction_density[0]