小编Tay*_*wte的帖子

tf.keras.utils.Sequence 中 __getitem__(...) 方法的索引参数是什么?

太长了;制作了自定义 tf.keras.utils.Sequence [ 1 ] 以将批量数据加载到keras.model.fit(...). 尽管超参数/模型/数据结构相同,但生成器的性能比从内存加载的数据调用模型时的性能要差得多。模型过度拟合,因此想知道从model.fit(...)[ 2 ] 方法到__getitem__(..., index)生成器中的方法的索引参数是否会导致相同的图像多次输入模型?如何选择索引参数?是订购的吗?最大索引是由 控制的吗__len(...)__

参考

  1. tf.keras.utils.序列
  2. keras.模型.fit

我正在使用 tf.keras.utils.Sequence [ 1 ]的子类将批量数据提供给 model.fit(...) 方法,如下所示。

class Generator(Sequence):
    
    def __init__(self, df, x, y, file_type, req_dim, directory, batch_size):
        # data info
        self.df = df
        self.x = self.df[x]  # path list to images being loaded
        self.y = self.df[y]  # corresponding target values
        self.index = self.df.index.to_list()
        self.directory = directory  # directory where features images are stored 
        self.file_type …
Run Code Online (Sandbox Code Playgroud)

python conv-neural-network keras tensorflow

5
推荐指数
1
解决办法
2391
查看次数

为什么在 RTX 3070/cudnn8/CUDA11.1 上运行时添加卷积/池层会导致 Keras/Tensorflow 模型崩溃?

系统信息

  • 操作系统:Windows 10,
  • 库德恩:8.0,
  • CUDA 工具包:11.1 安装在 10.2 之上,
  • GPU:Nvidia RTX 3070,
  • CPU:英特尔I7 10700f,
  • Tensorflow:(截至 2020 年 12 月 7 日tf.__version__==2.4.0rc-0也尝试过)tf-nightly-gpu
  • CUDA、cudnn 从源代码手动编译

测试代码

下面的代码成功编译了模型,但在model.fit(...)调用时崩溃了。


from tensorflow.keras import datasets, layers, models
import matplotlib.pyplot as plt

(train_images, train_labels), (test_images, test_labels) = datasets.cifar10.load_data()

train_images, test_images = train_images / 255.0, test_images / 255.0

model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu')) …
Run Code Online (Sandbox Code Playgroud)

python gpu keras tensorflow

3
推荐指数
1
解决办法
1719
查看次数

标签 统计

keras ×2

python ×2

tensorflow ×2

conv-neural-network ×1

gpu ×1