【问题标题】:How to fit data from InceptionV3 to ImageDataGenerator如何将 InceptionV3 中的数据拟合到 ImageDataGenerator
【发布时间】:2018-01-01 01:44:51
【问题描述】:

如何将 InceptionV3 中的数据拟合到 ImageDataGenerator?

我找到的将数据拟合到 ImageDataGenerator 的示例是 mnist 或 cifar10,如下所示:

(X_train, y_train), (X_test, y_test) = mnist.load_data()
# fit parameters from data
datagen.fit(X_train)

但是我可以将 InceptionV3 模型的数据拟合到我的 ImageDataGenerator 中吗?

我像这样加载我的 Inception V3 模型:

base_model = InceptionV3(weights='imagenet', include_top=True)
datagen = ImageDataGenerator(...)
datagen.fit(base_model.get_layer('avg_pool').output)

但我收到错误消息“ValueError: setting an array element with a sequence”。

【问题讨论】:

    标签: neural-network keras deep-linking


    【解决方案1】:

    我假设您需要分两步执行此操作。首先将您的数据输入 InceptionV3 模型并将输出保存到一个 numpy 数组中。然后将这个 numpy 数组输入到您的第二个模型中。

    这样的第一步(取自here):

    generator = datagen.flow_from_directory(
        'data/train',
        target_size=(150, 150),
        batch_size=batch_size,
        class_mode=None,  # this means our generator will only yield batches of data, no labels
        shuffle=False)  # our data will be in order
    
    bottleneck_features_train = model.predict_generator(generator, 2000)
    
    np.save(open('bottleneck_features_train.npy', 'w'), 
    

    bottleneck_features_train)

    【讨论】:

    • 这种方法的缺点是不能使用扩充。
    • 为什么不呢?您不能一次性完成,但是是什么阻碍了您进行图像增强运行,将增强后的图像保存到目录,从中间层保存 numpy 数组,然后继续执行第二个模型?
    猜你喜欢
    • 2022-06-10
    • 2019-11-27
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多