Cannot get predictions of tensorflow DNNClassifier

前端 未结 5 1549
无人及你
无人及你 2021-01-05 13:24

I\'m using the code from the MNIST tutorial:

feature_columns = [tf.contrib.layers.real_valued_column(\"\", dimension=4)]
classifier = tf.contrib.learn.DNNCla         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-05 14:25

    The DNNClassifier predict function by default have as_iterable=True. Thus, it returns an generator. For getting values of predictions instead of generator, pass as_iterable=False in classifier.predict method.

    For example,

    classifier.predict(input_fn = _my_predict_data,as_iterable=False)



    For understanding more about classifier methods and arguments. Here is a part of documentation for predict method.

    From DNNClassifier documentation:

    Predict

    Args:

    • x: features.
    • input_fn: Input function. If set, x must be None.
    • batch_size: Override default batch size.
    • outputs: list of str, name of the output to predict. If None, returns classes.
    • as_iterable: If True, return an iterable which keeps yielding predictions for each example until inputs are exhausted. Note: The inputs must terminate if you want the iterable to terminate (e.g. be sure to pass num_epochs=1 if you are using something like read_batch_features).

    Returns:

    • Numpy array of predicted classes with shape [batch_size] (or an iterable of predicted classes if as_iterable is True). Each predicted class is represented by its class index (i.e. integer from 0 to n_classes-1). If outputs is set, returns a dict of predictions.

提交回复
热议问题