1 Star 0 Fork 0

houkai2020/temp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.py 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
houkai 提交于 2020-04-03 19:26 . 1
import utils
import argparse
import numpy as np
import hparams_config
import efficientdet_arch
import tensorflow.compat.v1 as tf
def test(imgs, model_name, img_size=512):
raw_images, images, scales = [], [], []
for f in tf.io.gfile.glob(image_path_pattern):
image = Image.open(f)
raw_images.append(image)
image, scale = image_preprocess(image, image_size)
images.append(image)
scales.append(scale)
with tf.Session() as sess:
X = tf.placeholder(tf.float32, shape=(1, img_size, img_size, 3))
class_outputs, box_outputs = efficientdet_arch.efficientdet(X, model_name=model_name)
sess.run(tf.global_variables_initializer())
if tf.io.gfile.isdir(model_name):
model_name = tf.train.latest_checkpoint(model_name)
var_dict = utils.get_ema_vars()
tf.train.get_or_create_global_step()
sess.run(tf.global_variables_initializer())
saver = tf.train.Saver(var_dict, max_to_keep=1)
saver.restore(sess, model_name)
import time
times = []
for img in imgs:
img = img[np.newaxis, ...]
start = time.time()
sess.run(class_outputs, feed_dict={X: img})
spent = time.time() - start
print(spent)
times.append(spent)
print('mean time of 99 times: %.4f' % np.array(times[1:]).mean())
if __name__ == '__main__':
parser = argparse.ArgumentParser('test')
parser.add_argument('--model', type=str, default='0')
args = parser.parse_args()
model = 'efficientdet-d%s' % args.model
img_size = hparams_config.efficientdet_model_param_dict[model]['image_size']
test(, model, img_size=img_size)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/houkai2020/temp.git
git@gitee.com:houkai2020/temp.git
houkai2020
temp
temp
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385