Comments (2)
here is my test code
``# -- coding: UTF-8 --
from numpy import *
import operator
import os
from os import listdir
import sys
sys.path.append("/home/hj/caffe/python")
sys.path.append("/home/hj/caffe/python/caffe")
import caffe
import cv2
import numpy as np
val_file = '../densenet121_gap/test.txt'
data_root = ''
base_size = 234 # short size
crop_size = 224
def center_crop(img): # single crop
short_edge = min(img.shape[:2])
if short_edge < crop_size:
return
yy = int((img.shape[0] - crop_size) / 2)
xx = int((img.shape[1] - crop_size) / 2)
return img[yy: yy + crop_size, xx: xx + crop_size]
def test(my_project_root, deploy_proto):
caffe_model = my_project_root + 'vgg19_cvgj_iter_750.caffemodel'
net = caffe.Net(deploy_proto, caffe_model, caffe.TEST)
transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape})
transformer.set_transpose('data', (2,0,1))
#transformer.set_mean('data', np.load(root_str+'imagenet_mean.npy').mean(1).mean(1))
transformer.set_raw_scale('data', 255.0)
transformer.set_channel_swap('data', (2,1,0))
eval_images = []
ground_truth = []
f = open(val_file, 'r')
for i in f:
eval_images.append(i[:i.rindex(' ')])
ground_truth.append(int(i[i.rindex(' ')+1:]))
f.close()
ture_num=0.0
false_num=0.0
for idx,filename in enumerate(eval_images):
print filename
#im = caffe.io.load_image(filename,color=True)
_img = cv2.imread(data_root + eval_images[idx])
#print data_root + eval_images[i + skip_num]
#_img = cv2.resize(_img, (int(_img.shape[1] * base_size / min(_img.shape[:2])),
# int(_img.shape[0] * base_size / min(_img.shape[:2]))))
im = cv2.resize(_img, (base_size,base_size))
im=center_crop(im)
net.blobs['data'].data[...] = transformer.preprocess('data',im)
out = net.forward()
prob = net.blobs['prob'].data[0].flatten()
print "prob:",prob
order = prob.argsort()[-1]
if order==ground_truth[idx]:
ture_num+=1
else:
false_num+=1
print("true: %15s predict: %10s "%(ground_truth[idx], order))
print("accuracy:%.4f"%(ture_num/(ture_num+false_num)))
if name == 'main':
caffe.set_device(0)
caffe.set_mode_gpu()
my_project_root = '/home/hj/bingzao-detect/normal_abnormal_classify/vgg_bn_224/'
deploy_proto = my_project_root + "deploy.prototxt"
test(my_project_root, deploy_proto)
from cnn-models.
I didn't check in detail, but can't spot a problem right now. One thing I'm wondering: vgg19_cvgj_iter_750 means the model of iteration 750. Is that correct?
Another thing you can try is comparing the images loaded by the ImageDataLayer to the ones loaded with your script.
from cnn-models.
Related Issues (20)
- BN0 mean and variance HOT 1
- Why there is no scale layer after each batch norm layer? HOT 2
- Worse performance than the reported one in Res50 HOT 2
- Would you mind share resnet34.caffemodel? HOT 5
- Would you mind share labels file? HOT 3
- Would you mind sharing VGG16 model? HOT 2
- Difference between ResNet and VGG train.prototxt? HOT 2
- ResNet50: bottom blob of expand layer HOT 6
- VGG19BN: weird values of 'data/bn' parameters. HOT 2
- running VGG19_BN pretrained model need so much GPU memory HOT 3
- Where is the vgg16 pretrained modelS with BN? HOT 3
- can not reproduce validation accuracy with pretrained model
- Question about the license
- train on multi gpus HOT 2
- Unable to download model file from uni-jeana.de
- Check failed: target_blobs.size() == source_layer.blobs_size() (5 vs. 3) Incompatible number of blobs for layer data_bn
- No scale layers after batchnorm HOT 2
- Clarification on "validation set of ILSVRC 2012 - 2016 classiifcation task" HOT 1
- Regarding Image pre-processing. HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cnn-models.