tl.layers.DropoutLayer 用于构建 tf.estimator.Estimator,在训练/预测模式切换时出现错误 ‘ValueError: Variable model/relu1/W 不存在,或者没有使用 tf.get_variable() 创建。您是否想在 VarScope 中设置 reuse=tf.AUTO_REUSE?’
def model_fn(features, labels, mode, params): """ Model_fn for estimator model Args: features (Tensor): Input features to the model. labels (Tensor): Labels tensor for training and evaluation. mode (ModeKeys): Specifies if training, evaluation or prediction. params (HParams): hyper-parameters for estimator model Returns: (EstimatorSpec): Model to be run by Estimator. """ # check if training stage if mode == tf.estimator.ModeKeys.TRAIN: is_training = True reuse = False else: is_training = False reuse = True # is_training = False # 1 x = features logits = inference(x, reuse, is_training) predicted_classes = tf.argmax(logits, 1) # the maximum value in the predicted result is the class
内容来源: tensorlayer/TensorLayer