类 'augmentedImageDatastore' 没有恰当的方法、属性或字段 'Files'。
时间: 2024-01-14 21:04:41 浏览: 49
这个错误通常是因为你在调用 `Files` 属性时使用了错误的对象。`augmentedImageDatastore` 类并没有 `Files` 属性,因此如果你尝试访问它,就会出现这个错误。
如果你想获取 `augmentedImageDatastore` 中的文件名,请使用 `ReadFcn` 属性中提供的函数来读取图像,并使用 `getDataSource()` 方法获取数据源。
例如,你可以使用以下代码获取 `augmentedImageDatastore` 中的所有文件名:
```python
import os
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.preprocessing.image import img_to_array, load_img
datagen = ImageDataGenerator(rescale=1./255)
data_dir = 'path/to/dataset'
aug_data_dir = 'path/to/augmented_dataset'
# 创建augmentedImageDatastore
aug_ds = datagen.flow_from_directory(
data_dir,
target_size=(224, 224),
batch_size=32,
class_mode='categorical',
save_to_dir=aug_data_dir,
save_prefix='aug_',
save_format='jpeg'
)
# 获取augmentedImageDatastore中的所有文件名
file_names = []
for i in range(aug_ds.samples):
x, y = aug_ds.next()
for j in range(len(x)):
img = array_to_img(x[j])
file_names.append(os.path.basename(aug_ds.filenames[i*aug_ds.batch_size+j]))
print(file_names)
```
这段代码会将 `augmentedImageDatastore` 中的所有文件名存储在 `file_names` 列表中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)