简体   繁体   English

类型错误:__call__() 需要 1 到 2 个位置参数,但给出了 3 个

[英]TypeError: __call__() takes from 1 to 2 positional arguments but 3 were given

I'm trying to do mutli-label image classification and I'm trying to convert the image data set into TFRecords format.我正在尝试进行多标签图像分类,并且正在尝试将图像数据集转换为 TFRecords 格式。

Here is my Code:这是我的代码:

        def _bytes_feature(value):
          if isinstance(value,type(tf.cosntant(0))):
            value = value.numpy()
          return tf.train.Feature(byte_list=tf.train.BytesList(value=[value]))
        
        def _float_feature(value):
          return tf.train.Feature(float_list=tf.train.FloatList(value=[value]))
        
        def _int64_feature(value):
          return tf.train.Feature(int64_list = tf.train.Int64List(value=[value]))
        
        def image_example(image_string,image_name, df):
          image_shape = tf.image.decode_png(image_string).shape
          
          feature = {
          'height': _int64_feature(image_shape[0]),
          'width': _int64_feature(image_shape[1]),
          'depth': _int64_feature(image_shape[2]),
          'label_1': _int64_feature(df.loc(image_name,'Atelectasis')),
          'label_2': _int64_feature(df.loc(image_name,'Cardiomegaly')),
          'label_3': _int64_feature(df.loc(image_name,'Consolidation')),
          'label_4': _int64_feature(df.loc(image_name,'Edema')),
          'label_5': _int64_feature(df.loc(image_name,'Effusion')),
          'label_6': _int64_feature(df.loc(image_name,'Emphysema')),
          'label_7': _int64_feature(df.loc(image_name,'Fibrosis')),
          'label_8': _int64_feature(df.loc(image_name,'Hernia')),
          'label_9': _int64_feature(df.loc(image_name,'Infiltration')),
          'label_10': _int64_feature(df.loc(image_name,'Mass')),
          'label_11': _int64_feature(df.loc(image_name,'Nodule')),
          'label_12': _int64_feature(df.loc(image_name,'Pleural_Thickening')),
          'label_13': _int64_feature(df.loc(image_name,'Pneumonia')),
          'label_14': _int64_feature(df.loc(image_name,'Pneumothorax')),
          'label_15': _int64_feature(df.loc(image_name,'No Finding')),
          'image_raw': _bytes_feature(image_string),
          }
          return tf.train.example(features = tf.train.Features(feature=feature))


  

record_image = 'image.tfrecords'
with tf.io.TFRecordWriter(record_image) as write:
  for row in df.index:
    full_path = '/content/images/'+df['Image Index'][row]
    image_string = tf.io.read_file(full_path)
    image_name = pd.Series(df['Image Index'])[row]
    tf_example = image_example(image_string, image_name, df)
    write.write(tf_example.SerializeToString())

But it throws the error:但它抛出错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-66-f42cc357d799> in <module>()
      5     image_string = tf.io.read_file(full_path)
      6     image_name = pd.Series(df['Image Index'])[row]
----> 7     tf_example = image_example(image_string,image_name,df)
      8     write.write(tf_example.SerializeToString())

<ipython-input-64-de0476ade753> in image_example(image_string, image_name, df)
     17   'width': _int64_feature(image_shape[1]),
     18   'depth': _int64_feature(image_shape[2]),
---> 19   'label_1': _int64_feature(df.loc(image_name,'Atelectasis')),
     20   'label_2': _int64_feature(df.loc(image_name,'Cardiomegaly')),
     21   'label_3': _int64_feature(df.loc(image_name,'Consolidation')),

TypeError: __call__() takes from 1 to 2 positional arguments but 3 were given

Q1) Is it okay if I store the features like this? Q1) 如果我存储这样的功能可以吗? Cant the models from tensorflowHub understand it. tensorflowHub 的模型无法理解。 Can I "tell" the models what to expect as the input?我可以“告诉”模型期望输入什么吗?

Q2) Why am I getting that error? Q2)为什么我会收到那个错误? Image_example clearly takes 3 arguments. Image_example 显然需要 3 个参数。

df.loc(image_name,'X') 

需要是:

df.loc[image_name,'X']

暂无
暂无

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

相关问题 TypeError:__call __()接受2个位置参数,但给出了3个 - TypeError: __call__() takes 2 positional arguments but 3 were given WSGIServer TypeError:__call __()接受3个位置参数,但给出了4个 - WSGIServer TypeError: __call__() takes 3 positional arguments but 4 were given typeerror: __call__() 需要 2 个位置 arguments 但给出了 3 个(Gunicorn) - typeerror: __call__() takes 2 positional arguments but 3 were given (Gunicorn) TypeError: __init__() takes from 1 to 3 positional arguments but 4 were given - TypeError: __init__() takes from 1 to 3 positional arguments but 4 were given Money 和 TypeError:__init__() 需要 1 到 2 个位置参数,但给出了 3 个 - Money and TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given 类型错误:execute() 需要 2 到 3 个位置参数,但给出了 7 个 - TypeError: execute() takes from 2 to 3 positional arguments but 7 were given TypeError:send()接受1到2个位置参数,但给出了3个 - TypeError: send() takes from 1 to 2 positional arguments but 3 were given 类型错误:read_csv() 需要 0 到 1 个位置参数,但给出了 2 个 - TypeError: read_csv() takes from 0 to 1 positional arguments but 2 were given Python/MySQL TypeError:execute() 需要 2 到 4 个位置参数,但给出了 5 个 - Python/MySQL TypeError: execute() takes from 2 to 4 positional arguments but 5 were given TypeError:create()接受2个位置参数,但给出了4个 - TypeError: create() takes 2 positional arguments but 4 were given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM