tensorflow初步

为了学习语义分割,想学习一下tensorflow了。

tensorflow的官网为:

https://tensorflow.google.cn/




nvidia-docker run -it -p 8888:8888 -v /raid/zhaodz/tensorflow-latest/:/host  tensorflow/tensorflow:latest-gpu
可以通过jupyter运行tensorflow程序


nvidia-docker run -it -p 8888:8888 -v /raid/zhaodz/tensorflow-latest/:/host  tensorflow/tensorflow:latest-gpu /bin/bash
在shell中启动最新的 




https://tensorflow.google.cn/install/install_linux
安装教程




发现tensorflow安装位置
find . / -name tensorflow
/usr/local/lib/python2.7/dist-packages/tensorflow






1.鸢尾花实验
pip install pandas
更新pandas,不更新下载数据有问题
git clone https://github.com/tensorflow/models
下载示例代码
cd models/samples/core/get_started/
CUDA_VISIBLE_DEVICES=0  python premade_estimator.py(最好指定,否则默认全部有时候更慢)
指定cuda并运行
https://tensorflow.google.cn/get_started/premade_estimators 入门教程 
2.MNIST实验
cd cd models/tutorials/image/mnist
CUDA_VISIBLE_DEVICES=0  python convolutional.py
3.CIFAR10实验
cd models/tutorials/image/cifar10
CUDA_VISIBLE_DEVICES=0 python cifar10_train.py
https://tensorflow.google.cn/tutorials/deep_cnn
API
高阶API
Estimator
tf.layers之上构建
举例:DNNClassifier 
低阶API
tf.Graph
tf.Session


我们在使用tensorflow时,会发现tf.nn,tf.layers, tf.contrib模块有很多功能是重复的,尤其是卷积操作,在使用的时候,我们可以根据需要现在不同的模块。但有些时候可以一起混用。
下面是对三个模块的简述:


(1)tf.nn :提供神经网络相关操作的支持,包括卷积操作(conv)、池化操作(pooling)、归一化、loss、分类操作、embedding、RNN、Evaluation。


(2)tf.layers:主要提供的高层的神经网络,主要和卷积相关的,个人感觉是对tf.nn的进一步封装,tf.nn会更底层一些。


(3)tf.contrib:tf.contrib.layers提供够将计算图中的  网络层、正则化、摘要操作、是构建计算图的高级操作,但是tf.contrib包含不稳定和实验代码,有可能以后API会改变。




语言现象举例:
if __name__ == "__main__":  
tf.app.run()  
处理flag解析,然后执行main函数


tf.app.flags.DEFINE_integer('max_steps', 1000,
"""Number of batches to run.""")
解析参数

with tf.device('/cpu:0'):
设置器件
posted @ 2018-04-26 15:20  开往春天的拖拉机  阅读(106)  评论(0编辑  收藏  举报