日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tensorflow中关于vgg16的项目

發布時間:2023/12/18 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tensorflow中关于vgg16的项目 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉載請注明鏈接:http://www.cnblogs.com/SSSR/p/5630534.html

tflearn中的例子訓練vgg16項目:https://github.com/tflearn/tflearn/blob/master/examples/images/vgg_network.py 尚未測試成功。

下面的項目是使用別人已經訓練好的模型進行預測,測試效果非常好。

github:https://github.com/ry/tensorflow-vgg16 此項目已經測試成功,效果非常好,

如果在Ubuntu中的terminal中運行出現問題,可以參照以下部分解決(解決skimage讀取圖片的問題)。

#coding:utf-8import skimage import skimage.io import skimage.transform a=skimage.io.imread('cat.jpg') import PIL import numpy as np import tensorflow as tf synset = [l.strip() for l in open('/home/ubuntu/pythonproject/tensorflow/tensorflow-vgg16/synset.txt').readlines()]def load_image(path):# load imageimg = skimage.io.imread(path)#img1=PIL.Image.open("/home/ubuntu/pythonproject/tensorflow/tensorflow-vgg16/pic/pig.jpg")#img=np.array(PIL.Image.open(path))#imgx=np.array(img) #print type(imgx),imgx.shapeimg = img/ 255.0assert (0 <= img).all() and (img <= 1.0).all()#print "Original Image Shape: ", img.shape# we crop image from centershort_edge = min(img.shape[:2])yy = int((img.shape[0] - short_edge) / 2)xx = int((img.shape[1] - short_edge) / 2)crop_img = img[yy : yy + short_edge, xx : xx + short_edge]# resize to 224, 224resized_img = skimage.transform.resize(crop_img, (224, 224))return resized_img# returns the top1 string def print_prob(prob):#print probprint "prob shape", prob.shapepred = np.argsort(prob)[::-1]# Get top1 labeltop1 = synset[pred[0]]#print "Top1: ", top1# Get top5 labeltop5 = [synset[pred[i]] for i in range(5)]#print "Top5: ", top5return top1print u'加載模型文件' with open("/home/ubuntu/pythonproject/tensorflow/tensorflow-vgg16/vgg16.tfmodel", mode='rb') as f:fileContent = f.read()print u'創建圖' graph_def = tf.GraphDef() graph_def.ParseFromString(fileContent)images = tf.placeholder("float", [None, 224, 224, 3])tf.import_graph_def(graph_def, input_map={ "images": images }) print "graph loaded from disk"graph = tf.get_default_graph() print u'加載圖片' #img=np.array(PIL.Image.open("/home/ubuntu/pythonproject/tensorflow/tensorflow-vgg16/pic/pig.jpg")) #cat = load_image(path) print u'進入sess執行'sess=tf.Session() result=[] for i in ['cat.jpg','airplane.jpg','zebra.jpg','pig.jpg','12.jpg','23.jpg']:img=load_image('pic/'+i)init = tf.initialize_all_variables()sess.run(init)print "variables initialized"batch = img.reshape((1, 224, 224, 3))assert batch.shape == (1, 224, 224, 3)feed_dict = { images: batch }print u'開始執行'prob_tensor = graph.get_tensor_by_name("import/prob:0")prob = sess.run(prob_tensor, feed_dict=feed_dict)print u'輸出結果'#print_prob(prob[0])result.append(print_prob(prob[0]))print result sess.close()''' with tf.Session() as sess:init = tf.initialize_all_variables()sess.run(init)print "variables initialized"batch = cat.reshape((1, 224, 224, 3))assert batch.shape == (1, 224, 224, 3)feed_dict = { images: batch }print u'開始執行'prob_tensor = graph.get_tensor_by_name("import/prob:0")prob = sess.run(prob_tensor, feed_dict=feed_dict)print u'輸出結果' print_prob(prob[0])'''

  

轉載于:https://www.cnblogs.com/SSSR/p/5630534.html

總結

以上是生活随笔為你收集整理的tensorflow中关于vgg16的项目的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。