mac下tensorflow的helloworld

基本的
virtualenv tensorenv
source bin/activate

pip install --upgrade tensorflow

python
>>> import tensorflow as tf
>>> hello = tf.constant('hello TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
hello TensorFlow!



tensorenv/lib/python2.7/site-packages/tensorflow/examples/tutorials/mnist


#########################

[b]安装anaconda[/b]

[url]https://www.anaconda.com/download/#macos[/url]


安装之后参考
[url]https://blog.csdn.net/lq_547762983/article/details/81003528[/url]


conda list

conda create -n tensorenv tensorflow
conda env list


创建名字为tensorenv 的环境并安装tensorflow
安装在/anaconda2/envs 下
/anaconda2/envs/tensorenv




source activate tensorenv




如果需要装其他包继续
conda install -n tensorenv numpy



下载数据:
参考[url]http://wiki.jikexueyuan.com/project/tensorflow-zh/tutorials/mnist_beginners.html[/url]

https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/examples/tutorials/mnist/input_data.py
添加
import tensorflow.examples.tutorials.mnist.input_data as input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

用自己的网,网络限制就想其他办法


反向传播
梯度下降


dropout 解决泛化性不好

无监督学习 [url]https://www.zhihu.com/question/23194489[/url]


##################
使用的tf1.0的版本,很多api变了

第一个helloworld

[code]
import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

a = tf.constant(5,name="input_a")
b = tf.constant(3,name="input_b")
c = tf.multiply(a,b,name="mul_c")
d = tf.add(a,b,name="add_d")
e = tf.add(c,d,name="add_e")
sess = tf.Session()
sess.run(e)

#writer = tf.train.SummaryWriter('./my_grap',sess.graph)
writer = tf.summary.FileWriter('./my_graph',sess.graph)
writer.close()
sess.close()
[/code]

[code]
tensorboard --logdir="./my_graph"
[/code]

得到[img]http://dl2.iteye.com/upload/attachment/0130/8785/269c4015-a141-3e98-bb7e-021446bc66e0.png[/img]

张量的helloworld
test2.py
[code]
import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

a = tf.constant([5,3],name="input_a")
b = tf.reduce_prod(a,name="prod_b")
c = tf.reduce_sum(a,name="sum_c")
d = tf.add(c,b,name="add_d")
sess = tf.Session()
sess.run(d)

writer = tf.summary.FileWriter('./my_test2',sess.graph)
writer.close()
sess.close()
[/code]

numpy的helloworld

注意:numpy使用字符串时,不要显示的指定dtype属性


基本概念
tensor -->numpy建立 a = tf.constant(3,name="input_b")
opration ---> b = tf.add(a,3) ;
graph ---> g=tf.Graph() g.as_default()
session --->sess = ts.Session(graph = tf.get_default_graph())
fetches ---->sesion.run(a) ;sesion.run([a,b])
feed_dict ----> sesion.run(b,feed_dict = {a:15}) ---改变参数的值,测试和中间环节改变值调试用,或者是给占位符赋值
placeholder(dtype,shape,name) ---> tf.placeholder(tf.int32,shape=[2]) ---> dtype参数是必须指定的

[code]
import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

a = tf.add(2,5)
b = tf.multiply(a,3)

sess = tf.Session()
replace_dict = {a:15}

c = sess.run(b,feed_dict=replace_dict)
print(c)
[/code]


基本机器学习
basic.py
[code]
import tensorflow as tf
import numpy as np
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

def inference(X):
print("inference")

def loss(X,Y):
print("loss")
loss_v = tf.constant("myloss",name="loss_value")
return loss_v

def inputs():
print("input")
return 1,2

def train(total_loss):
print("train")
hello = tf.constant("ha",name="train_value")
return hello

def evaluate(sess,X,Y):
print("evaluate")


with tf.Session() as sess:
# tf.initialize_all_variables().run()
tf.global_variables_initializer().run()
X,Y = inputs()

total_loss = loss(X,Y)
train_op = train(total_loss)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess,coord=coord)
training_steps = 100
for step in range(training_steps):
sess.run([train_op])
if step % 10 ==0:
print("loss:",sess.run([total_loss]))
evaluate(sess,X,Y)

coord.request_stop()
coord.join(threads)
sess.close()
[/code]


检查点,针对变量的
注意:变量不能放在定义的方法里
saver要放在初始化变量之后
check.py
[code]
import tensorflow as tf
import numpy as np
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

def inference(X):
print("inference")

def loss(X,Y):
print("loss")
return X

def inputs(X):
print("input")
Y = tf.constant("myY",name="Y_value")
return X,Y

def train(total_loss):
print("train")
hello = tf.constant("ha",name="train_value")
return hello

def evaluate(sess,X,Y):
print("evaluate")
with tf.Session() as sess:
#tf.global_variables_initializer().run()
thisX = tf.Variable("thisX",name="thisX_value")
sess.run(tf.global_variables_initializer())
saver = tf.train.Saver()
X,Y = inputs(thisX)

total_loss = loss(X,Y)
train_op = train(total_loss)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess,coord=coord)
training_steps = 100
for step in range(training_steps):
sess.run([train_op])
if step % 10 ==0:
print("loss:",sess.run([total_loss]))
saver.save(sess,'./work/my-model',global_step=step)
evaluate(sess,X,Y)

coord.request_stop()
coord.join(threads)
saver.save(sess,'./work/my-model',global_step=training_steps)
sess.close()
[/code]

恢复检查点
restore.py

[code]
import tensorflow as tf
import numpy as np
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

def inference(X):
print("inference")

def loss(X,Y):
print("loss")
return X

def inputs(X):
print("input")
Y = tf.constant("myY",name="Y_value")
return X,Y

def train(total_loss):
print("train")
hello = tf.constant("ha",name="train_value")
return hello

def evaluate(sess,X,Y):
print("evaluate")
with tf.Session() as sess:
#tf.global_variables_initializer().run()
thisX = tf.Variable("thisX",name="thisX_value")
sess.run(tf.global_variables_initializer())
saver = tf.train.Saver()
X,Y = inputs(thisX)

total_loss = loss(X,Y)
train_op = train(total_loss)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess,coord=coord)
training_steps = 1000

initial_step = 0
ckpt = tf.train.get_checkpoint_state(os.path.dirname("./work/my-model"))
print("debug---->0 "+str(ckpt))
if ckpt and ckpt.model_checkpoint_path:
print("debug---->1")
saver.restore(sess,ckpt.model_checkpoint_path)
initial_step = int(ckpt.model_checkpoint_path.rsplit('-',1)[1])
print("debug---->2.1 " + str(initial_step))
print("debug---->2.2 " + str(initial_step))
for step in range( initial_step,training_steps):
print("debug---->3")
sess.run([train_op])
if step % 10 ==0:
print("loss:",sess.run([total_loss]))
saver.save(sess,'./work/my-model',global_step=step)
evaluate(sess,X,Y)

coord.request_stop()
coord.join(threads)
saver.save(sess,'./work/my-model',global_step=training_steps)
sess.close()
[/code]
关于saver

[url]https://www.tensorflow.org/programmers_guide/saved_model?hl=zh-cn[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园整体解决方案是响应国家教育信息化政策,结合教育改革和技术创新的产物。该方案以物联网、大数据、人工智能和移动互联技术为基础,旨在打造一个安全、高效、互动且环保的教育环境。方案强调从数字化校园向智慧校园的转变,通过自动数据采集、智能分析和按需服务,实现校园业务的智能化管理。 方案的总体设计原则包括应用至上、分层设计和互联互通,确保系统能够满足不同用户角色的需求,并实现数据和资源的整合与共享。框架设计涵盖了校园安全、管理、教学、环境等多个方面,构建了一个全面的校园应用生态系统。这包括智慧安全系统、校园身份识别、智能排课及选课系统、智慧学习系统、精品录播教室方案等,以支持个性化学习和教学评估。 建设内容突出了智慧安全和智慧管理的重要性。智慧安全管理通过分布式录播系统和紧急预案一键启动功能,增强校园安全预警和事件响应能力。智慧管理系统则利用物联网技术,实现人员和设备的智能管理,提高校园运营效率。 智慧教学部分,方案提供了智慧学习系统和精品录播教室方案,支持专业级学习硬件和智能化网络管理,促进个性化学习和教学资源的高效利用。同时,教学质量评估中心和资源应用平台的建设,旨在提升教学评估的科学性和教育资源的共享性。 智慧环境建设则侧重于基于物联网的设备管理,通过智慧教室管理系统实现教室环境的智能控制和能效管理,打造绿色、节能的校园环境。电子班牌和校园信息发布系统的建设,将作为智慧校园的核心和入口,提供教务、一卡通、图书馆等系统的集成信息。 总体而言,智慧校园整体解决方案通过集成先进技术,不仅提升了校园的信息化水平,而且优化了教学和管理流程,为学生、教师和家长提供了更加便捷、个性化的教育体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值