简体   繁体   English

类型错误:float() 参数必须是字符串或数字,而不是“模块”

[英]TypeError: float() argument must be a string or a number, not 'module'

Any help will be appreciated.任何帮助将不胜感激。 I am trying to "define the expected input shape" as a part of a tutorial model which you can find on this website: ( https://machinelearningmastery.com/how-to-perform-object-detection-with-yolov3-in-keras/ ).我正在尝试“定义预期的输入形状”作为您可以在本网站上找到的教程模型的一部分:( https://machinelearningmastery.com/how-to-perform-object-detection-with-yolov3-in -keras/ )。 The code I am using is as below:我使用的代码如下:

# load and prepare an image
def load_image_pixels(filename, shape):
    # load the image to get its shape
    Image_file = image.load_img(filename)
    width, height = Image_file.size
    # load the image with the required size
    Image_file = image.load_img(filename, target_size=shape)
    # convert to numpy array
    Image_file = image.img_to_array(image)
    # scale pixel values to [0, 1]
    Image_file = Image_file.astype('float32')
    Image_file /= 255.0
    # add a dimension so that we have one sample
    Image_file = expand_dims(Image_file, 0)
    return Image_file, width, height

# define the expected input shape for the model
input_w, input_h = 416, 416
# define our new photo
filename = 'zebra.jpg'
# load and prepare image
Image_file, width, height = load_image_pixels(filename, (input_w, input_h))

And I am getting the following error:我收到以下错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-12-ea4c5aa676a6> in <module>
      4 filename = 'zebra.jpg'
      5 # load and prepare image
----> 6 Image_file, width, height = load_image_pixels(filename, (input_w, input_h))

<ipython-input-11-2ab602af7690> in load_image_pixels(filename, shape)
      7     Image_file = image.load_img(filename, target_size=shape)
      8     # convert to numpy array
----> 9     Image_file = image.img_to_array(image)
     10     # scale pixel values to [0, 1]
     11     Image_file = Image_file.astype('float32')

~/anaconda3/lib/python3.7/site-packages/keras/preprocessing/image.py in img_to_array(img, data_format, dtype)
     73     if dtype is None:
     74         dtype = backend.floatx()
---> 75     return image.img_to_array(img, data_format=data_format, dtype=dtype)
     76 
     77 

~/anaconda3/lib/python3.7/site-packages/keras_preprocessing/image/utils.py in img_to_array(img, data_format, dtype)
    297     # or (channel, height, width)
    298     # but original PIL image has format (width, height, channel)
--> 299     x = np.asarray(img, dtype=dtype)
    300     if len(x.shape) == 3:
    301         if data_format == 'channels_first':

~/anaconda3/lib/python3.7/site-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
     83 
     84     """
---> 85     return array(a, dtype, copy=False, order=order)
     86 
     87 

TypeError: float() argument must be a string or a number, not 'module'

Your image should be Image_file in Image_file = image.img_to_array(image) .您的image应该是Image_file Image_file = image.img_to_array(image)中的Image_file = image.img_to_array(image) So this line should be Image_file = image.img_to_array(Image_file)所以这一行应该是Image_file = image.img_to_array(Image_file)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:float() 参数必须是字符串或数字,而不是“PolyCollection” - TypeError: float() argument must be a string or a number, not 'PolyCollection' Python 错误:TypeError:float() 参数必须是字符串或实数,而不是“列表” - Python error: TypeError: float() argument must be a string or a real number, not 'list' 类型错误:float() 参数必须是字符串或数字,而不是“datetime.timedelta” - TypeError: float() argument must be a string or a number, not 'datetime.timedelta' Python-TypeError:float()参数必须是字符串或数字,而不是&#39;list - Python - TypeError: float() argument must be a string or a number, not 'list 类型错误:float() 参数必须是字符串或数字,而不是“元组” ValueError:使用序列设置数组元素 - TypeError: float() argument must be a string or a number, not 'tuple' ValueError: setting an array element with a sequence “TypeError:float参数必须是字符串或数字,而不是列表。”将字符串列表转换为浮点列表 - “TypeError: float argument must be a string or a number, not a list.” converting a list of strings to a list of floats LabelEncoder — TypeError:参数必须是字符串或数字 - LabelEncoder — TypeError: argument must be a string or number sklearn knn预测错误:float()参数必须是字符串或数字,而不是&#39;dict&#39; - sklearn knn prediction error: float() argument must be a string or a number, not 'dict' TypeError:参数必须是字符串或数字列上的字符串或数字 - TypeError: argument must be a string or number on column with strings that are numbers 类型错误:strptime() 参数 1 必须是 str,而不是浮点数 - TypeError: strptime() argument 1 must be str, not float
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM