tensorflow的contrib的基本用法和自定义模型
来源:互联网 发布:java 返回数组给前台 编辑:程序博客网 时间:2024/05/29 12:10
tensorflow的contrib.learn的基本用法
import tensorflow as tf# NumPy is often used to load, manipulate and preprocess data.import numpy as np# Declare list of features. We only have one real-valued feature. There are many# other types of columns that are more complicated and useful.features = [tf.contrib.layers.real_valued_column("x", dimension=1)]# An estimator is the front end to invoke training (fitting) and evaluation# (inference). There are many predefined types like linear regression,# logistic regression, linear classification, logistic classification, and# many neural network classifiers and regressors. The following code# provides an estimator that does linear regression.estimator = tf.contrib.learn.LinearRegressor(feature_columns=features)# TensorFlow provides many helper methods to read and set up data sets.# Here we use `numpy_input_fn`. We have to tell the function how many batches# of data (num_epochs) we want and how big each batch should be.x = np.array([1., 2., 3., 4.])y = np.array([0., -1., -2., -3.])input_fn = tf.contrib.learn.io.numpy_input_fn({"x":x}, y, batch_size=4, num_epochs=1000)# We can invoke 1000 training steps by invoking the `fit` method and passing the# training data set.estimator.fit(input_fn=input_fn, steps=1000)# Here we evaluate how well our model did. In a real example, we would want# to use a separate validation and testing data set to avoid overfitting.print(estimator.evaluate(input_fn=input_fn))
contrib的自定义模型
import numpy as npimport tensorflow as tf# Declare list of features, we only have one real-valued featuredef model(features, labels, mode): # Build a linear model and predict values W = tf.get_variable("W", [1], dtype=tf.float64) b = tf.get_variable("b", [1], dtype=tf.float64) y = W*features['x'] + b # Loss sub-graph loss = tf.reduce_sum(tf.square(y - labels)) # Training sub-graph global_step = tf.train.get_global_step() optimizer = tf.train.GradientDescentOptimizer(0.01) train = tf.group(optimizer.minimize(loss), tf.assign_add(global_step, 1)) # ModelFnOps connects subgraphs we built to the # appropriate functionality. return tf.contrib.learn.ModelFnOps( mode=mode, predictions=y, loss=loss, train_op=train)estimator = tf.contrib.learn.Estimator(model_fn=model)# define our data setx = np.array([1., 2., 3., 4.])y = np.array([0., -1., -2., -3.])input_fn = tf.contrib.learn.io.numpy_input_fn({"x": x}, y, 4, num_epochs=1000)# trainestimator.fit(input_fn=input_fn, steps=1000)# evaluate our modelprint(estimator.evaluate(input_fn=input_fn, steps=10))
1 0
- tensorflow的contrib的基本用法和自定义模型
- tensorflow的基本用法
- TensorFlow的基本用法
- TensorFlow的基本用法
- Tensorflow的基本用法
- tensorflow的基本用法
- tensorflow的基本用法(二)
- tensorflow的基本用法(三)
- tensorflow的基本用法(一)
- tensorflow的基本用法(二)
- Tensorflow的一些基本用法
- Tensorflow的一些基本用法
- UICollectionView和自定义UICollectionViewCell的基本用法
- tensorflow的基本用法(一)
- 自定义dialog的基本用法
- tensorflow 的模型保存和调用
- 6.TensorFlow模型的保存和读取
- TensorFlow模型的保存和持久化
- python3 selenium 切换窗口的几种方法
- QT 界面几点总结
- 垃圾收集器
- OKHttp源码分析(三)之ResponseBody
- 登录界面(Android studio)
- tensorflow的contrib的基本用法和自定义模型
- Android WebView与JS交互及消息处理
- 两种网络模式简单实现Netcat
- Tomcat Core与Deployer版本有什么区别的相关推荐
- 利用set对list进行合并去重复
- NoSQL introduction
- css3 box-sizing属性
- 设计模式Builder模式——java设计模式——建造者模式
- 机器学习入门之基本软件安装