TF学习——TF之API:TensorFlow的高级机器学习API—tf.contrib.learn的简介、使用方法、案例应用之详细攻略

简介: TF学习——TF之API:TensorFlow的高级机器学习API—tf.contrib.learn的简介、使用方法、案例应用之详细攻略

tf.contrib.learn的简介




tf.contrib.learn 是 TensorFlow 提供的一个机器学习高级 API 模块,让用户可以更方便的配置、训练和评估各种各样的机器学习模型,里面内置了很多模型可以直接调用,其实,就是类似最经典的机器学习库 scikit-learn 的 API 。很多调用方法都很相同。


1、常用的模型


线性分类 tf.contrib.learn.LinearClassifier

线性回归 tf.contrib.learn.LinearRegressor

逻辑斯谛回归 tf.contrib.learn.LogisticRegressor

K-means 聚类 tf.contrib.learn.KMeansClustering

神经网络分类器 tf.contrib.learn.DNNClassifier

神经网络回归器 tf.contrib.learn.DNNRegressor

广度深度回归 tf.contrib.learn.DNNLinearCombinedRegressor

广度深度分类 tf.contrib.learn.DNNLinearCombinedClassifier

注意:该模块已被弃用,请仔细查看API说明,https://github.com/tensorflow/tensorflow/blob/r1.13/tensorflow/contrib/learn/README.md

Many canned estimators (subclasses of Estimator) have equivalents in core exposed under tf.estimator: DNNClassifier, DNNRegressor, DNNEstimator, LinearClassifier, LinearRegressor, LinearEstimator, DNNLinearCombinedClassifier,DNNLinearCombinedRegressor and DNNLinearCombinedEstimator.


To migrate to the new api, users need to take the following steps:

Replace tf.contrib.learn with tf.estimator.



tf.contrib.learn的使用方法


Modules


datasets module: Dataset utilities and synthetic/reference datasets (deprecated).

graph_actions module: High level operations on graphs (deprecated).

head module: Abstractions for the head(s) of a model (deprecated).

io module: Tools to allow different io formats (deprecated).

learn_runner module: Utilities to run and tune an Experiment (deprecated).

models module: Various high level TF models (deprecated).

monitors module: Monitors instrument the training process (deprecated).

ops module: Various TensorFlow Ops (deprecated).

preprocessing module: Preprocessing tools useful for building models (deprecated).

utils module: TensorFlow Learn Utils (deprecated).


Classes


class BaseEstimator: Abstract BaseEstimator class to train and evaluate TensorFlow models.

class DNNClassifier: A classifier for TensorFlow DNN models.

class DNNEstimator: A Estimator for TensorFlow DNN models with user specified _Head.

class DNNLinearCombinedClassifier: A classifier for TensorFlow Linear and DNN joined training models.

class DNNLinearCombinedEstimator: An estimator for TensorFlow Linear and DNN joined training models.

class DNNLinearCombinedRegressor: A regressor for TensorFlow Linear and DNN joined training models.

class DNNRegressor: A regressor for TensorFlow DNN models.

class DynamicRnnEstimator: Dynamically unrolled RNN (deprecated).

class Estimator: Estimator class is the basic TensorFlow model trainer/evaluator.

class Evaluable: Interface for objects that are evaluatable by, e.g., Experiment.

class Experiment: Experiment is a class containing all information needed to train a model.

class ExportStrategy: A class representing a type of model export.

class Head: Interface for the head/top of a model.

class InputFnOps: A return type for an input_fn (deprecated).

class KMeansClustering: An Estimator for K-Means clustering.

class LinearClassifier: Linear classifier model.

class LinearEstimator: Linear model with user specified head.

class LinearRegressor: Linear regressor model.

class MetricSpec: MetricSpec connects a model to metric functions.

class ModeKeys: Standard names for model modes (deprecated).

class ModelFnOps: Ops returned from a model_fn.

class NanLossDuringTrainingError: Unspecified run-time error.

class NotFittedError: Exception class to raise if estimator is used before fitting.

class PredictionKey: THIS CLASS IS DEPRECATED.

class ProblemType: Enum-like values for the type of problem that the model solves.

class RunConfig: This class specifies the configurations for an Estimator run.

class SKCompat: Scikit learn wrapper for TensorFlow Learn Estimator.

class SVM: Support Vector Machine (SVM) model for binary classification.

class TaskType: DEPRECATED CLASS.

class Trainable: Interface for objects that are trainable by, e.g., Experiment.


Functions


LogisticRegressor(...): Builds a logistic regression Estimator for binary classification.

binary_svm_head(...): Creates a Head for binary classification with SVMs. (deprecated)

build_parsing_serving_input_fn(...): Build an input_fn appropriate for serving, expecting fed tf.Examples. (deprecated)

evaluate(...): Evaluate a model loaded from a checkpoint. (deprecated)

extract_dask_data(...): Extract data from dask.Series or dask.DataFrame for predictors. (deprecated)

extract_dask_labels(...): Extract data from dask.Series or dask.DataFrame for labels. (deprecated)

extract_pandas_data(...): Extract data from pandas.DataFrame for predictors. (deprecated)

extract_pandas_labels(...): Extract data from pandas.DataFrame for labels. (deprecated)

extract_pandas_matrix(...): Extracts numpy matrix from pandas DataFrame. (deprecated)

infer(...): Restore graph from restore_checkpoint_path and run output_dict tensors. (deprecated)

infer_real_valued_columns_from_input(...): Creates FeatureColumn objects for inputs defined by input x. (deprecated)

infer_real_valued_columns_from_input_fn(...): Creates FeatureColumn objects for inputs defined by input_fn. (deprecated)

make_export_strategy(...): Create an ExportStrategy for use with Experiment. (deprecated)

multi_class_head(...): Creates a Head for multi class single label classification. (deprecated)

multi_head(...): Creates a MultiHead stemming from same logits/hidden layer. (deprecated)

multi_label_head(...): Creates a Head for multi label classification. (deprecated)

no_op_train_fn(...): DEPRECATED FUNCTION

poisson_regression_head(...): Creates a Head for poisson regression. (deprecated)

read_batch_examples(...): Adds operations to read, queue, batch Example protos. (deprecated)

read_batch_features(...): Adds operations to read, queue, batch and parse Example protos. (deprecated)

read_batch_record_features(...): Reads TFRecord, queues, batches and parses Example proto. (deprecated)

read_keyed_batch_examples(...): Adds operations to read, queue, batch Example protos. (deprecated)

read_keyed_batch_examples_shared_queue(...): Adds operations to read, queue, batch Example protos. (deprecated)

read_keyed_batch_features(...): Adds operations to read, queue, batch and parse Example protos. (deprecated)

read_keyed_batch_features_shared_queue(...): Adds operations to read, queue, batch and parse Exampleprotos.(deprecated)

regression_head(...): Creates a Head for linear regression. (deprecated)

run_feeds(...): See run_feeds_iter(). Returns a list instead of an iterator. (deprecated)

run_n(...): Run output_dict tensors n times, with the same feed_dict each run. (deprecated)

train(...): Train a model. (deprecated)



tf.contrib.learn的案例应用


更新……


 


相关文章
|
人工智能 JSON 自然语言处理
如何用大模型评估大模型——PAI-Judge裁判员大语言模型的实现简介
阿里云人工智能平台 PAI 推出 PAI-Judge 裁判员大模型,为用户构建符合应用场景的多维度、细粒度的评测体系,支持单模型评测和双模型竞技两种模式,允许用户自定义参数,实现准确、灵活、高效的模型自动化评测,为模型迭代优化提供数据支撑。 相比通用大模型尤其在回答确定性/数学类问题、角色扮演、创意文体写作、翻译等场景下,PAI-Judge 系列模型表现优异,可以直接用于大模型的评估与质检。
|
机器学习/深度学习 算法 TensorFlow
交通标志识别系统Python+卷积神经网络算法+深度学习人工智能+TensorFlow模型训练+计算机课设项目+Django网页界面
交通标志识别系统。本系统使用Python作为主要编程语言,在交通标志图像识别功能实现中,基于TensorFlow搭建卷积神经网络算法模型,通过对收集到的58种常见的交通标志图像作为数据集,进行迭代训练最后得到一个识别精度较高的模型文件,然后保存为本地的h5格式文件。再使用Django开发Web网页端操作界面,实现用户上传一张交通标志图片,识别其名称。
1097 7
交通标志识别系统Python+卷积神经网络算法+深度学习人工智能+TensorFlow模型训练+计算机课设项目+Django网页界面
|
机器学习/深度学习 人工智能 TensorFlow
基于TensorFlow的深度学习模型训练与优化实战
基于TensorFlow的深度学习模型训练与优化实战
842 3
|
机器学习/深度学习 TensorFlow API
机器学习实战:TensorFlow在图像识别中的应用探索
【10月更文挑战第28天】随着深度学习技术的发展,图像识别取得了显著进步。TensorFlow作为Google开源的机器学习框架,凭借其强大的功能和灵活的API,在图像识别任务中广泛应用。本文通过实战案例,探讨TensorFlow在图像识别中的优势与挑战,展示如何使用TensorFlow构建和训练卷积神经网络(CNN),并评估模型的性能。尽管面临学习曲线和资源消耗等挑战,TensorFlow仍展现出广阔的应用前景。
541 5
|
机器学习/深度学习 人工智能 算法
【手写数字识别】Python+深度学习+机器学习+人工智能+TensorFlow+算法模型
手写数字识别系统,使用Python作为主要开发语言,基于深度学习TensorFlow框架,搭建卷积神经网络算法。并通过对数据集进行训练,最后得到一个识别精度较高的模型。并基于Flask框架,开发网页端操作平台,实现用户上传一张图片识别其名称。
1058 0
【手写数字识别】Python+深度学习+机器学习+人工智能+TensorFlow+算法模型
|
机器学习/深度学习 人工智能 算法
【玉米病害识别】Python+卷积神经网络算法+人工智能+深度学习+计算机课设项目+TensorFlow+模型训练
玉米病害识别系统,本系统使用Python作为主要开发语言,通过收集了8种常见的玉米叶部病害图片数据集('矮花叶病', '健康', '灰斑病一般', '灰斑病严重', '锈病一般', '锈病严重', '叶斑病一般', '叶斑病严重'),然后基于TensorFlow搭建卷积神经网络算法模型,通过对数据集进行多轮迭代训练,最后得到一个识别精度较高的模型文件。再使用Django搭建Web网页操作平台,实现用户上传一张玉米病害图片识别其名称。
372 0
【玉米病害识别】Python+卷积神经网络算法+人工智能+深度学习+计算机课设项目+TensorFlow+模型训练
|
持续交付 测试技术 jenkins
JSF 邂逅持续集成,紧跟技术热点潮流,开启高效开发之旅,引发开发者强烈情感共鸣
【8月更文挑战第31天】在快速发展的软件开发领域,JavaServer Faces(JSF)这一强大的Java Web应用框架与持续集成(CI)结合,可显著提升开发效率及软件质量。持续集成通过频繁的代码集成及自动化构建测试,实现快速反馈、高质量代码、加强团队协作及简化部署流程。以Jenkins为例,配合Maven或Gradle,可轻松搭建JSF项目的CI环境,通过JUnit和Selenium编写自动化测试,确保每次构建的稳定性和正确性。
322 0
|
缓存 开发者 测试技术
跨平台应用开发必备秘籍:运用 Uno Platform 打造高性能与优雅设计兼备的多平台应用,全面解析从代码共享到最佳实践的每一个细节
【8月更文挑战第31天】Uno Platform 是一种强大的工具,允许开发者使用 C# 和 XAML 构建跨平台应用。本文探讨了 Uno Platform 中实现跨平台应用的最佳实践,包括代码共享、平台特定功能、性能优化及测试等方面。通过共享代码、采用 MVVM 模式、使用条件编译指令以及优化性能,开发者可以高效构建高质量应用。Uno Platform 支持多种测试方法,确保应用在各平台上的稳定性和可靠性。这使得 Uno Platform 成为个人项目和企业应用的理想选择。
452 0
|
API UED 开发者
如何在Uno Platform中轻松实现流畅动画效果——从基础到优化,全方位打造用户友好的动态交互体验!
【8月更文挑战第31天】在开发跨平台应用时,确保用户界面流畅且具吸引力至关重要。Uno Platform 作为多端统一的开发框架,不仅支持跨系统应用开发,还能通过优化实现流畅动画,增强用户体验。本文探讨了Uno Platform中实现流畅动画的多个方面,包括动画基础、性能优化、实践技巧及问题排查,帮助开发者掌握具体优化策略,提升应用质量与用户满意度。通过合理利用故事板、减少布局复杂性、使用硬件加速等技术,结合异步方法与预设缓存技巧,开发者能够创建美观且流畅的动画效果。
517 0
|
UED 存储 数据管理
深度解析 Uno Platform 离线状态处理技巧:从网络检测到本地存储同步,全方位提升跨平台应用在无网环境下的用户体验与数据管理策略
【8月更文挑战第31天】处理离线状态下的用户体验是现代应用开发的关键。本文通过在线笔记应用案例,介绍如何使用 Uno Platform 优雅地应对离线状态。首先,利用 `NetworkInformation` 类检测网络状态;其次,使用 SQLite 实现离线存储;然后,在网络恢复时同步数据;最后,通过 UI 反馈提升用户体验。
582 0

热门文章

最新文章