fix the bug of epistemic model

pull/8699/head
bingyaweng 4 years ago
parent 20b5172893
commit 2cf2acc26f

@ -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
@ -109,7 +110,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())
@ -238,7 +239,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
@ -246,7 +247,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.")

Loading…
Cancel
Save