young.y_y 2019-06-11 14:22 采纳率: 0%
浏览 816
已结题

tensorflow 在feed的时候报错could not convert string to float

报错ValueError: could not convert string to float: 'C:/Users/Administrator/Desktop/se//12.21/FV-USM/Published_database_FV-USM_Dec2013/1st_session/extractedvein/vein001_1/01.jpg'
以下是我的代码

```#!/usr/bin/env python

-*- coding:utf-8 -*-

import tensorflow as tf
from PIL import Image
import model
import numpy as np
import os

def get_one_image():

i=1
n=1
k=1
i = str(i)
n = str(n)
k = str(k)
a = i.zfill(3)
b = n.zfill(1)
c = k.zfill(2)
files='C:/Users/Administrator/Desktop/se//12.21/FV-USM/Published_database_FV-USM_Dec2013/1st_session/extractedvein/vein' + a + '_' + b + '/' + c + '.jpg'

# image=image.resize([60,175])
# image=np.array(image)
return files

def evaluate_one_image():
image_array = get_one_image()

with tf.Graph().as_default():
    BATCH_SIZE=1
    N_CLASS=123
    image = tf.image.decode_jpeg(image_array, channels=1)
    image = tf.image.resize_image_with_crop_or_pad(image,60, 175)
    image = tf.image.per_image_standardization(image)  ###图片调整完成
    # image=tf.cast(image,tf.string)
    # image1 = tf.image.decode_jpeg(image, channels=1)
    # image1 = tf.image.resize_image_with_crop_or_pad(image1, image_w, image_h)
    #image1 = tf.image.per_image_standardization(image)  ###图片调整完成

    #image=tf.image.per_image_standardization(image)

    image = tf.cast(image, tf.float32)

    image=tf.reshape(image,[1,60,175,1])
    logit = model.inference(image, BATCH_SIZE, N_CLASS)
    logit=tf.nn.softmax(logit) # 因为 inference 的返回没有用激活函数,所以在这里对结果用softmax 激活。但是为什么要激活??
    x=tf.placeholder(tf.float32,shape=[60,175,1])
    logs_model_dir='C:/Users/Administrator/Desktop/python的神经网络/model/'
    saver=tf.train.Saver()
    with tf.Session() as sess:
        print("从指定路径加载模型。。。")
        ckpt=tf.train.get_checkpoint_state(logs_model_dir)
        if ckpt and ckpt.model_checkpoint_path:
            global_step=ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
            saver.restore(sess,ckpt.model_checkpoint_path)
            print('模型加载成功,训练步数为 %s'%global_step)
        else:
            print('模型加载失败,,,,文件没有找到')
        ###IMG = sess.run(image)
        prediction=sess.run(logit,feed_dict={x:image_array})
        max_index=np.argmax(prediction)
        print(max_index)

evaluate_one_image()

  • 写回答

2条回答 默认 最新

  • threenewbee 2019-06-11 15:22
    关注

    ,feed_dict={x:image_array} 需要的是浮点数,你传入的是字符串,类型不对

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题