0

障害があると指定された関数を呼び出していなくても、コードが Jupyter Notebook で AttributionError をスローし続けるという問題に直面しています。私のpythonコードは次のとおりです。

 import numpy as np
 import matplotlib
 matplotlib.use('nbagg')
 import matplotlib.pyplot as plt
 import seaborn as sns
 import pandas as pd 
 import os
 from PIL import Image

cube_features = []
 for cube in cubes:
df_cube = pd.read_csv(cube_base + 'props_cube{}.csv'.format(cube),
                        names=['cube', 'phi_x', 'phi_y', 'fir_x', 'fir_y', 'bush_x', 'bush_y', 'sun_x', 'sun_y', 'poplar_x', 'poplar_y', 'img_path'])
area_features = [] 
for area in areas:
    if area == 'Moc':
        features = []
        for row in df_cube['img_path']:
            image = Image.open(row).convert('RGB')
            features.append(np.array(image).flatten())
        features = np.array(features)
    else:
        features_dict = np.atleast_1d(np.load('/Users/tol/Features/CORnetZ/cube{}_CORnet-Z_{}_output_feats.npy'.format(cube, area), allow_pickle=True))[0]
        if not all(np.array(features_dict['fnames']) == df_cube['img_path'].values): 
            raise ValueError('My Error')
        features = features_dict['model_feats']
    print('Cube {}, Area {} - Representation size {}'.format(cube, area, features.shape))
    #area_corr = pd.DataFrame(features.transpose()).corr() # num_images x num_images
    area_features.append(features)
cube_features.append(area_features)

私のエラーコードは次のとおりです。

    AttributeError                            Traceback (most recent call last)
  /opt/anaconda3/lib/python3.8/site-packages/PIL/Image.py in open(fp, mode, formats)
   2894     try:
 -> 2895         fp.seek(0)
   2896     except (AttributeError, io.UnsupportedOperation):

    AttributeError: 'float' object has no attribute 'seek'

    During handling of the above exception, another exception occurred:

    AttributeError                            Traceback (most recent call last)
    <ipython-input-43-31c8f89d4a7f> in <module>
       8             features = []
       9             for row in df_cube['img_path']:
     ---> 10                 image = Image.open(row).convert('RGB')
      11                 features.append(np.array(image).flatten())
      12             features = np.array(features)

    /opt/anaconda3/lib/python3.8/site-packages/PIL/Image.py in open(fp, mode, formats)
     2895         fp.seek(0)
     2896     except (AttributeError, io.UnsupportedOperation):
     -> 2897         fp = io.BytesIO(fp.read())
     2898         exclusive_fp = True
     2899 

     AttributeError: 'float' object has no attribute 'read'

誰かがこれで私を助けてくれることを本当に願っています! ありがとう!

4

1 に答える 1