![](/img/trans.png)
[英]TypeError: __call__() takes 2 positional arguments but 3 were given
[英]TypeError: __call__() takes from 1 to 2 positional arguments but 3 were given
我正在嘗試進行多標簽圖像分類,並且正在嘗試將圖像數據集轉換為 TFRecords 格式。
這是我的代碼:
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())
但它拋出錯誤:
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) 如果我存儲這樣的功能可以嗎? tensorflowHub 的模型無法理解。 我可以“告訴”模型期望輸入什么嗎?
Q2)為什么我會收到那個錯誤? Image_example 顯然需要 3 個參數。
df.loc(image_name,'X')
需要是:
df.loc[image_name,'X']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.