def build_objective(model, deterministic=False, epsilon=1e-12):
predictions = nn.layers.get_output(model.l_out, deterministic=deterministic)
targets = T.cast(nn.layers.get_output(model.l_target), 'int32')
enable_targets = nn.layers.get_output(model.l_enable_target)
predictions = T.clip(predictions, epsilon, 1.-epsilon)
#is_nodule_ground_truth = T.cast(targets[:,0], 'float32')
sum_of_objectives = 0
unit_ptr = 0
for obj_idx, obj_name in enumerate(order_objectives):
n_classes = len(property_bin_borders[obj_name])
v_obj = objective(obj_idx, (unit_ptr, unit_ptr+n_classes), predictions, targets)
if deterministic:
d_objectives_deterministic[obj_name] = T.mean(v_obj)
else:
d_objectives[obj_name] = T.mean(v_obj)
#sum_of_objectives += T.mean(enable_targets[obj_idx] * v_obj)
sum_of_objectives += T.mean(enable_targets[:,obj_idx] * v_obj)
unit_ptr = unit_ptr+n_classes
#print 'for debug purposes: unit_ptr', unit_ptr
return sum_of_objectives
评论列表
文章目录