c++调用vgg16:
./build/install/bin/classification \
/media/whale/wsWin10/wsCaffe/model-zoo/VGG16//deploy.prototxt \
/media/whale/wsWin10/wsCaffe/model-zoo/VGG16/VGG_ILSVRC_16_layers.caffemodel \
data/ilsvrc12/imagenet_mean.binaryproto \
/media/whale/wsWin10/wsCaffe/model-zoo/VGG16/synset_words.txt \
/media/whale/wsWin10/images/person/2.jpg
然后就报错了。
然后
whale@sea:/media/whale/wsWin10/wsUbuntu16./DlFrames/caffe$ ./build/install/bin/classification /media/whale/wsWin10/wsCaffe/model-zoo/VGG16//deploy.prototxt /media/whale/wsWin10/wsCaffe/model-zoo/VGG16/VGG_ILSVRC_16_layers.caffemodel data/ilsvrc12/imagenet_mean.binaryproto ./3labels.txt /media/whale/wsWin10/images/person/2.jpg
labels_.size() = output_layer->channels() = ---------- Prediction for /media/whale/wsWin10/images/person/.jpg ----------
0.3333 - ""
0.3333 - ""
0.3333 - ""
whale@sea:/media/whale/wsWin10/wsUbuntu16./DlFrames/caffe$ ./build/install/bin/classification /media/whale/wsWin10/wsCaffe/model-zoo/VGG16//deploy.prototxt /media/whale/wsWin10/wsCaffe/model-zoo/VGG16/VGG_ILSVRC_16_layers.caffemodel data/ilsvrc12/imagenet_mean.binaryproto ./3labels.txt /media/whale/wsWin10/images/person/3.jpg
labels_.size() = output_layer->channels() = ---------- Prediction for /media/whale/wsWin10/images/person/.jpg ----------
0.3333 - ""
0.3333 - ""
0.3333 - ""
只能给3个标签,不然就报错。然后,。。。,这个模型是假的吗?
还是什么是假的?
keras-python调用vgg16:
python-keras接口调用模型要简单些,只需要标签文件,和keras模型就可以了。
from keras.applications.vgg16 import VGG16
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input
from keras.models import Model
import numpy as np
import matplotlib.pyplot as plt
img_path = './data/elephant.jpg'
img_path = '/media/whale/wsWin10/images/dog/0c02094a98d126cf541c4318188699a5.jpg'
img_path = '/media/whale/wsWin10/images/dog/dd92db98b99479db3619f62c724757a4.jpg'
img = image.load_img(img_path, target_size=(224, 224))
plt.imshow(img)
plt.show( )
model = VGG16(include_top=True, weights='imagenet')
print(" type(model) = ", type(model))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
print( "x.max() = ", x.max())
scores = model.predict(x)
class_table = open('./data/synset_words', 'r')
lines = class_table.readlines()
print(" scores type: ", type(scores))
print(" scores shape: ", scores.shape)
print(" np.argmax(scores) = ", np.argmax(scores))
print('result is ', lines[np.argmax(scores)])
class_table.close()
import sys
sys.exit()
。。。/wsWin10/wsPycharm/sklearnStu/Keras-Tutorials/08.vgg-16.py
Using TensorFlow backend.
2018-01-16 17:35:28.541700: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-01-16 17:35:28.627059: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:892] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-01-16 17:35:28.627317: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Found device 0 with properties:
name: GeForce GTX 850M major: 5 minor: 0 memoryClockRate(GHz): 0.9015
pciBusID: 0000:01:00.0
totalMemory: 3.95GiB freeMemory: 3.63GiB
2018-01-16 17:35:28.627334: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 850M, pci bus id: 0000:01:00.0, compute capability: 5.0)
(' type(model) = ',
('x.max() = ', 151.061)
(' scores type: ',
(' scores shape: ', (1, 1000))
(' np.argmax(scores) = ', 235)
('result is ', 'n02106662 German shepherd, German shepherd dog, German police dog, alsatian\n')
Process finished with exit code 0
翻译下: 德国牧羊犬,德国牧羊犬,德国警犬,阿尔萨斯
手机扫一扫
移动阅读更方便
你可能感兴趣的文章