Giter Site home page Giter Site logo

Comments (2)

zbxzc35 avatar zbxzc35 commented on August 16, 2024

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.

MarcelSimon avatar MarcelSimon commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.