tensorflow 加载预训练模型
来源:互联网 发布:单片机小车制作流程 编辑:程序博客网 时间:2024/05/18 15:30
加载预训练模型需要具备两个条件:1.框架结构(知道每一层的名字),2. 预训练好的模型文件.ckpt
加载预训练模型代码如下:
import tensorflowas tf
import numpy as np
weights_1 = tf.Variable(tf.zeros([3,4]))
# weights_2 = tf.Variable(tf.zeros([4,3]))
sess = tf.InteractiveSession()
saver = tf.train.Saver()
saver.restore(sess, '/tmp/checkpoint/model.ckpt')
o_test = np.array([[4.0,3.0, 2.0]], dtype='float32')
label = tf.matmul(o_test, weights_1)
# label = tf.matmul(label, weights_2)
print sess.run(label)
以上为加载模型代码,可以写全变量名,也可只写一部分。可根据输出来定。
其中,model.ckpt训练模型代码如下:
import tensorflowas tf
import numpy as np
i_data = np.array([[5.0,3.0, 2.0]], dtype= 'float32')
i_label= np.array([[15.0,10.0, 22.0]], dtype= 'float32')
weights_1 = tf.Variable(tf.zeros([3,4]))
out_1 = tf.matmul(i_data, weights_1)
weights_2 = tf.Variable(tf.zeros([4,3]))
out = tf.matmul(out_1, weights_2)
init_op = tf.global_variables_initializer()
saver = tf.train.Saver()
loss = tf.reduce_mean(tf.square(out- i_label))
training = tf.train.GradientDescentOptimizer(0.01).minimize(loss)
sess = tf.Session()
sess.run(init_op)
for i in range(20000):
sess.run(training)
save_path = saver.save(sess,'/tmp/checkpoint/model.ckpt')
阅读全文
0 0
- tensorflow 加载预训练模型
- Tensorflow加载预训练模型和保存模型
- TensorFlow保存和加载训练模型
- tensorflow保存加载模型查看训练参数
- TensorFlow保存和加载训练模型
- TensorFlow保存和加载训练模型
- tensorflow学习笔记六:保存和加载训练模型
- java加载tensorflow训练好的模型部署成service
- TensorFlow VGG-16 预训练模型
- tensorflow 模型训练
- Tensorflow训练卷积神经网络并保存模型,加载模型并导入手写图片测试
- tensorflow ssd mobilenet模型训练
- TensorFlow on Android:训练模型
- 如何用Tensorflow训练模型成pb文件和和如何加载已经训练好的模型文件
- pytorch 如何加载部分预训练模型
- github上tensorflow预训练模型下载链接
- Tensorflow 05: 导入预训练好的图模型
- TensorFlow学习笔记(2)——保存和加载训练模型参数
- 段错误原因分析和查找
- 使用java程序启动,停止本地应用
- DMZ主机作用
- 数据结构与算法C++描述(1)---线性表的基本操作
- Calendar
- tensorflow 加载预训练模型
- ListView优化
- CGI 和fastcgi一级php-fpm
- python 装饰器1
- 微信小程序picker组件下拉框选择某个值动态添加input输入框
- iPhoneX的faceID到底是一种怎样风骚的操作?
- c# 怎样实现用几张图片制作 gif?怎样对图片像素值进行修改?上代码
- SIGSEGV与SIGBUS
- [js高手之路]Vue2.0基于vue-cli+webpack父子组件通信教程