tensorflow(四)caffe-tensorflow学习记录
tensorflow
一个面向所有人的开源机器学习框架
项目地址:https://gitcode.com/gh_mirrors/te/tensorflow

·
按照Lenet里面的例子进行模型和网络的转换:
LeNet Example
Thanks to @Russell91 for this example
This example showns you how to finetune code from the Caffe MNIST tutorial using Tensorflow.
First, you can convert a prototxt model to tensorflow code:
$ ./convert.py examples/mnist/lenet.prototxt --code-output-path=mynet.py
This produces tensorflow code for the LeNet network in mynet.py
. The code can be imported as described below in the Inference section. Caffe-tensorflow also lets you convert .caffemodel
weight files to .npy
files that can be directly loaded from tensorflow:
$ ./convert.py examples/mnist/lenet.prototxt --caffemodel examples/mnist/lenet_iter_10000.caffemodel --data-output-path=mynet.npy
The above command will generate a weight file named mynet.npy
.
Inference:
tensorflow
一个面向所有人的开源机器学习框架
项目地址:https://gitcode.com/gh_mirrors/te/tensorflow
Once you have generated both the code weight files for LeNet, you can finetune LeNet using tensorflow with
$ ./examples/mnist/finetune_mnist.py
At a high level, finetune_mnist.py
works as follows:
# Import the converted model's class
from mynet import MyNet
# Create an instance, passing in the input data
net = MyNet({'data':my_input_data})
with tf.Session() as sesh:
# Load the data
net.load('mynet.npy', sesh)
# Forward pass
output = sesh.run(net.get_output(), ...)
经过转换之后的代码:(自己添加的代码)
import numpy as np
from PIL import Image
import tensorflow as tf
import sys
sys.path.append('/home/yang/caffe-tensorflow')
sys.path.append('/home/yang/caffe-tensorflow/examples/yolo')
import yolo
image = tf.placeholder(tf.float32, [1,448,448,3])
net = yolo.yolo({'data': image})
image_path = '/home/yang/darknet/data/dog.jpg'
im = Image.open(image_path)
im_reshape = im.resize((448,448))
input = np.array(im_reshape)
input = input.reshape((1,448,448,3))
input = (input*1.0-127.5)*0.007874015748031496
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
net.load('/home/yang/caffe-tensorflow/examples/yolo/yolo.npy', sess)
output = sess.run(net.get_output(), feed_dict={image: input})
file = open('/home/yang/Desktop/result.txt','w')
for i in range(1470):
file.write(str(output[0][i])+' ')
file.close()
附加mnist测试代码:
import sys
sys.path.append('/home/yang/caffe-tensorflow/examples/mnist')
sys.path.append('/home/yang/tensorflow')
sys.path.append('/home/yang/caffe-tensorflow')
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('/home/yang/data', one_hot=True)
from mynet import LeNet as MyNet
image = tf.placeholder(tf.float32, [1, 784])
labels = tf.placeholder(tf.float32, [1, 10])
input = tf.reshape(image, shape=[-1, 28, 28, 1])
net = MyNet({'data': input})
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
net.load('/home/yang/caffe-tensorflow/examples/mnist/mynet.npy', sess)
batch_xs, batch_ys = mnist.train.next_batch(1)
output = sess.run(net.get_output(), feed_dict={image: batch_xs})
阅读全文
AI总结




一个面向所有人的开源机器学习框架
最近提交(Master分支:1 个月前 )
4f64a3d5
Instead, check for this case in `ResolveUsers` and `ResolveOperand`, by querying whether the `fused_expression_root` is part of the `HloFusionAdaptor`.
This prevents us from stepping into nested fusions.
PiperOrigin-RevId: 724311958
1 个月前
aa7e952e
Fix a bug in handling negative strides, and add a test case that exposes it.
We can have negative strides that are not just -1, e.g. with a combining
reshape.
PiperOrigin-RevId: 724293790
1 个月前
更多推荐
相关推荐
查看更多
tensorflow

一个面向所有人的开源机器学习框架
tensorflow

TensorFlow for R
tensorflow

热门开源项目
活动日历
查看更多
直播时间 2025-03-13 18:32:35

全栈自研企业级AI平台:Java核心技术×私有化部署实战
直播时间 2025-03-11 18:35:18

从0到1:Go IoT 开发平台的架构演进与生态蓝图
直播时间 2025-03-05 14:35:37

国产工作流引擎 终结「996」开发困局!
直播时间 2025-02-25 14:38:13

免费开源宝藏 ShopXO,电商系统搭建秘籍大公开!
直播时间 2025-02-18 14:31:04

从数据孤岛到数据智能 - 企业级数据管理利器深度解析
所有评论(0)