NotImplementedError:尚未为未构建的Model子类启用`fit_generator` [英] NotImplementedError: `fit_generator` is not yet enabled for unbuilt Model subclasses

查看:501
本文介绍了NotImplementedError:尚未为未构建的Model子类启用`fit_generator`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码:

import tensorflow as tf
##############################################################

traindata = tf.keras.preprocessing.image.ImageDataGenerator(
    rescale=1. / 255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True)

input = traindata.flow_from_directory('VS/train')

    modelo = tf.keras.Sequential()
    modelo.add(tf.keras.layers.Conv2D(32, (3, 3), 
 activation=tf.keras.activations.relu))
    modelo.add(tf.keras.layers.Flatten())
    modelo.add(tf.keras.layers.Dense(64, activation=tf.keras.activations.relu))
    modelo.add(tf.keras.layers.Dense(2, activation=tf.keras.activations.relu))
    modelo.compile(loss='categorical_crossentropy', optimizer='rmsprop')

modelo.fit_generator(input, epochs=1)

但是,我遇到此错误:

因此,通过运行下面的代码,我会收到此错误

So by running the code below I get this error

NotImplementedError: `fit_generator` is not yet enabled for unbuilt Model subclasses 

有人可以告诉我怎么了吗?

Can someone tell me what's wrong?

推荐答案

您没有在第一层中指定input_shape,因此该模型未完全定义. fit_generator尚未实现此过程,因此您应该使用初始input_shape完全定义模型.

You didn't specify the input_shape in the first layer, so the model is not fully defined. This process has not been implemented with fit_generator, so you should fully define the model with the initial input_shape.

这篇关于NotImplementedError:尚未为未构建的Model子类启用`fit_generator`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆