|
|
|
@ -47,6 +47,7 @@ class UncertaintyEvaluation:
|
|
|
|
|
Default: None.
|
|
|
|
|
epochs (int): Total number of iterations on the data. Default: 1.
|
|
|
|
|
epi_uncer_model_path (str): The save or read path of the epistemic uncertainty model. Default: None.
|
|
|
|
|
If the epi_uncer_model_path is 'Untrain', the epistemic model need not to be trained.
|
|
|
|
|
ale_uncer_model_path (str): The save or read path of the aleatoric uncertainty model. Default: None.
|
|
|
|
|
save_model (bool): Whether to save the uncertainty model or not, if true, the epi_uncer_model_path
|
|
|
|
|
and ale_uncer_model_path must not be None. If false, the model to evaluate will be loaded from
|
|
|
|
@ -111,7 +112,7 @@ class UncertaintyEvaluation:
|
|
|
|
|
"""
|
|
|
|
|
if self.epi_uncer_model is None:
|
|
|
|
|
self.epi_uncer_model = EpistemicUncertaintyModel(self.epi_model)
|
|
|
|
|
if self.epi_uncer_model.drop_count == 0:
|
|
|
|
|
if self.epi_uncer_model.drop_count == 0 and self.epi_uncer_model_path != 'Untrain':
|
|
|
|
|
if self.task_type == 'classification':
|
|
|
|
|
net_loss = SoftmaxCrossEntropyWithLogits(sparse=True, reduction="mean")
|
|
|
|
|
net_opt = Adam(self.epi_uncer_model.trainable_params())
|
|
|
|
@ -240,7 +241,7 @@ class EpistemicUncertaintyModel(Cell):
|
|
|
|
|
for (name, layer) in epi_model.name_cells().items():
|
|
|
|
|
if isinstance(layer, Dropout):
|
|
|
|
|
self.drop_count += 1
|
|
|
|
|
return epi_model
|
|
|
|
|
return epi_model
|
|
|
|
|
for (name, layer) in epi_model.name_cells().items():
|
|
|
|
|
if isinstance(layer, (Conv2d, Dense)):
|
|
|
|
|
uncertainty_layer = layer
|
|
|
|
@ -248,7 +249,7 @@ class EpistemicUncertaintyModel(Cell):
|
|
|
|
|
drop = Dropout(keep_prob=dropout_rate)
|
|
|
|
|
bnn_drop = SequentialCell([uncertainty_layer, drop])
|
|
|
|
|
setattr(epi_model, uncertainty_name, bnn_drop)
|
|
|
|
|
return epi_model
|
|
|
|
|
return epi_model
|
|
|
|
|
raise ValueError("The model has not Dense Layer or Convolution Layer, "
|
|
|
|
|
"it can not evaluate epistemic uncertainty so far.")
|
|
|
|
|
|
|
|
|
|