栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何用我自己的图像喂入Cifar10训练过的模型并获得标签作为输出?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何用我自己的图像喂入Cifar10训练过的模型并获得标签作为输出?

首先要了解一些基础知识:

  1. 首先定义图表:图像队列,图像预处理,卷积推理,top-k精度
  2. 然后创建一个,
    tf.Session()
    并在其中进行操作:启动队列运行器,并调用
    sess.run()

这是您的代码应为的样子

# 1. GRAPH CREATION filename_queue = tf.train.string_input_producer(['/home/tensor/.../inputImage.jpg'])...  # NO CREATION of a tf.Session herefloat_image = ...images = tf.expand_dims(float_image, 0)  # create a fake batch of images (batch_size=1)logits = faultnet.inference(images)_, top_k_pred = tf.nn.top_k(logits, k=5)# 2. TENSORFLOW SESSIonwith tf.Session() as sess:    sess.run(init_op)    coord = tf.train.Coordinator()    threads = tf.train.start_queue_runners(coord=coord)    top_indices = sess.run([top_k_pred])    print ("Predicted ", top_indices[0], " for your input image.")

编辑:

正如@mrry所建议的,如果只需要处理 单个 图像,则可以删除队列运行器:

# 1. GRAPH CREATIONinput_img = tf.image.depre_jpeg(tf.read_file("/home/.../your_image.jpg"), channels=3)reshaped_image = tf.image.resize_image_with_crop_or_pad(tf.cast(input_img, width, height), tf.float32)float_image = tf.image.per_image_withening(reshaped_image)images = tf.expand_dims(float_image, 0)  # create a fake batch of images (batch_size = 1)logits = faultnet.inference(images)_, top_k_pred = tf.nn.top_k(logits, k=5)# 2. TENSORFLOW SESSIonwith tf.Session() as sess:  sess.run(init_op)  top_indices = sess.run([top_k_pred])  print ("Predicted ", top_indices[0], " for your input image.")


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/661538.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号