Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test model get very low accuracy #16

Open
iodncookie opened this issue Dec 13, 2019 · 8 comments
Open

test model get very low accuracy #16

iodncookie opened this issue Dec 13, 2019 · 8 comments

Comments

@iodncookie
Copy link

hi,i had try my model use 90 epochs.here is my result:
image
but when i run test.py,i get very low accuracy,
image

i am so confused.i wonder know is something wrong?

@iodncookie
Copy link
Author

@dontfollowmeimcrazy

@matteo-dunnhofer
Copy link
Owner

Hi @iodncookie, sorry for the late reply!

Are you sure to have loaded the right checkpoint of the model?

@iodncookie
Copy link
Author

iodncookie commented Jan 8, 2020

@dontfollowmeimcrazy
thanks for your reply。
yes, i am sure loaded the right checkpoint of the model,and here is my test.py code:

import os.path
import tensorflow as tf
import train_util as tu
from models import alexnet
import numpy as np
import logging
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '1'

logging.basicConfig(level=logging.INFO,
filename='test_loger.log',
filemode='w',
format='%(asctime)s %(message)s ',
datefmt='%Y-%m-%d %H:%M:%S',
)

def test(
top_k,
k_patches,
display_step,
imagenet_path,
ckpt_path):

test_images = sorted(os.listdir(os.path.join(imagenet_path, 'val')))
test_labels = tu.read_test_labels(os.path.join(imagenet_path, 'data/ILSVRC2012_validation_ground_truth.txt'))

test_examples = len(test_images)

x = tf.placeholder(tf.float32, [None, 224, 224, 3])
y = tf.placeholder(tf.float32, [None, 1000])

# _, pred = alexnet.classifier(x, 1.0)
_, pred = alexnet.darknet53_classifier(x,False)
# calculate the average precision of the crops of the image
avg_prediction = tf.div(tf.reduce_sum(pred, 0), k_patches)

# accuracy
top1_correct = tf.equal(tf.argmax(avg_prediction, 0), tf.argmax(y, 1))
top1_accuracy = tf.reduce_mean(tf.cast(top1_correct, tf.float32))

topk_correct = tf.nn.in_top_k(tf.stack([avg_prediction]), tf.argmax(y, 1), k=top_k)
topk_accuracy = tf.reduce_mean(tf.cast(topk_correct, tf.float32))

saver = tf.train.Saver()

with tf.Session(config=tf.ConfigProto()) as sess:
	saver.restore(sess, os.path.join(ckpt_path, 'darknet_prune_77_0.7422.ckpt'))

	total_top1_accuracy = 0.
	total_topk_accuracy = 0.

	for i in range(test_examples):
		# taking a few patches from an image
		image_patches = tu.read_k_patches(os.path.join(imagenet_path, 'val', test_images[i]), k_patches)
		label = test_labels[i]

		top1_a, topk_a = sess.run([top1_accuracy, topk_accuracy], feed_dict={x: image_patches, y: [label]})
		total_top1_accuracy += top1_a
		total_topk_accuracy += topk_a

		if i % display_step == 0:
			info = 'Examples done: {:5d}/{} ---- Top-1: {:.4f} -- Top-{}: {:.4f}'.format(i + 1, test_examples, total_top1_accuracy / (i + 1), top_k, total_topk_accuracy / (i + 1))
			print(info)
			logging.info(info)
	print ('---- Final accuracy ----')
	info = 'Top-1: {:.4f} -- Top-{}: {:.4f}'.format(total_top1_accuracy / test_examples, top_k, total_topk_accuracy / test_examples)
	print(info)
	logging.info(info)
	info = 'Top-1 error rate: {:.4f} -- Top-{} error rate: {:.4f}'.format(1 - (total_top1_accuracy / test_examples), top_k, 1 - (total_topk_accuracy / test_examples))
	print(info)
	logging.info(info)

if name == 'main':
TOP_K = 5
K_PATCHES = 5
DISPLAY_STEP = 10
IMAGENET_PATH = '/home/yons/work/imagenet'
CKPT_PATH = 'ckpt-darknet-prune'

test( 
	TOP_K, 
	K_PATCHES, 
	DISPLAY_STEP,
	IMAGENET_PATH,
	CKPT_PATH)

@ghost
Copy link

ghost commented Feb 27, 2020

I have the same problem

@matteo-dunnhofer
Copy link
Owner

Hi @iodncookie
Are you training and testing a different model than the AlexNet present in the repo? I noticed this line in the code you pasted
_, pred = alexnet.darknet53_classifier(x,False)

@codinggirl-abc are you doing something similar?

@iodncookie
Copy link
Author

Hi @iodncookie
Are you training and testing a different model than the AlexNet present in the repo? I noticed this line in the code you pasted
_, pred = alexnet.darknet53_classifier(x,False)

@codinggirl-abc are you doing something similar?

yes,i am training a prune darknet model. i am still strugle with this problem.

@matteo-dunnhofer
Copy link
Owner

Have you tried to train AlexNet? Does it give you the same problem?

@iodncookie
Copy link
Author

Have you tried to train AlexNet? Does it give you the same problem?
not yet.train a model almost take me two weeks,so i just directly train my own model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants