“您的输入数据用完”总是在第 # 次时代

如何解决“您的输入数据用完”总是在第 # 次时代

我一直在尝试使用 Keras 为 model.fit() 制作我的第一个数据生成器。我试图制作的数据集有两个输入,一个图像和一个浮点值。我所有的图像名称和值都存储在一个 csv 文件中。我相信我错误地制作了我的生成器,因为无论我的批量大小是多少,我总是在与我的时代相同的步骤中收到错误“您的输入用完了数据”。因此,如果我的 epochs 设置为 100,我的模型将运行到第 100 步。我的数据集大约有 100000 个图像/值。如果有人能帮我找到一个很好的解决方案。
我目前正在使用:
蟒蛇 3.8
TF-GPU 2.4.0rc1
keras 2.4.3
熊猫 1.1.4

代码:

IMG_SIZE = 400
Version = 1
batch_size = 64
val = .05

val_aug = ImageDataGenerator(rescale=1/255)
aug = ImageDataGenerator(
        rescale=1/255,rotation_range=30,width_shift_range=0.1,height_shift_range=0.1,shear_range=0.2,zoom_range=0.2,channel_shift_range=25,horizontal_flip=True,fill_mode='constant')


df = pd.read_csv('F:/DATA/Vote/Vote_Age.csv')

df = df.sample(frac = 1)
cut = int(len(df) * val)

train_df = df[cut:]
val_df = df[0:cut]
print(f'Training dataset: {len(train_df)}')
print(f'Val dataset: {len(val_df)}')

train_steps = int(len(train_df) / batch_size)
val_steps = int(len(val_df) / batch_size)

def data(df,generator,batch_size,IMG_SIZE):
        z = 0
        while True:
                df = df.sample(frac = 1)
                for i in range(int(len(df) / batch_size)):
                        images,ages,votes = [],[],[]
                        for x in range(batch_size):
                                csv_row = df.iloc[(z),:]
                                z += 1
                                image_path = f'F:/DATA/Vote/Images/{int(csv_row[0])}.jpg'
                                image = cv2.resize(cv2.imread(image_path),(int(IMG_SIZE),int(IMG_SIZE)))
                                image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
                                image = image.reshape(-1,IMG_SIZE,3)
                                generator.fit(image)
                                image = generator.flow(image,batch_size=1)
                                image = image.next()
                                image = image.reshape(IMG_SIZE,3)

                                images.append(image)
                                ages.append(csv_row[1])
                                votes.append(int(csv_row[2]))

                        images = np.array(images)
                        ages = np.array(ages)
                        votes = np.array(votes)
                
                        return [[images,ages],[votes]]

#########
#Model was very big and unnecessary to include
#########

train_dataset = train_data(train_df,IMG_SIZE)
val_dataset = val_data(val_df,IMG_SIZE)

model.fit(
    x = train_dataset[0],y = train_dataset[1],validation_data=(val_dataset[0],val_dataset[1]),steps_per_epoch=train_steps,validation_steps=val_steps,callbacks=earlyStop,epochs=100,batch_size=batch_size,workers=multiprocessing.cpu_count(),verbose=1)

model.save(f'F:/DATA/Vote/Models/YiffModel{Version}')

输出:

...
  83/1484 [>.............................] - ETA: 4:46 - loss: 7578.7731
  84/1484 [>.............................] - ETA: 4:46 - loss: 7575.5172
  85/1484 [>.............................] - ETA: 4:46 - loss: 7572.2818
  86/1484 [>.............................] - ETA: 4:46 - loss: 7569.0662
  87/1484 [>.............................] - ETA: 4:46 - loss: 7565.8702
  88/1484 [>.............................] - ETA: 4:45 - loss: 7562.6932
  89/1484 [>.............................] - ETA: 4:45 - loss: 7559.5349
  90/1484 [>.............................] - ETA: 4:45 - loss: 7556.3948
  91/1484 [>.............................] - ETA: 4:45 - loss: 7553.2726
  92/1484 [>.............................] - ETA: 4:44 - loss: 7550.1679
  93/1484 [>.............................] - ETA: 4:44 - loss: 7547.0802
  94/1484 [>.............................] - ETA: 4:44 - loss: 7544.0094
  95/1484 [>.............................] - ETA: 4:44 - loss: 7540.9549
  96/1484 [>.............................] - ETA: 4:43 - loss: 7537.9164
  97/1484 [>.............................] - ETA: 4:43 - loss: 7534.8937
  98/1484 [>.............................] - ETA: 4:43 - loss: 7531.8863
  99/1484 [=>............................] - ETA: 4:43 - loss: 7528.8939
 100/1484 [=>............................] - ETA: 4:43 - loss: 7525.9163
WARNING:tensorflow:Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least `steps_per_epoch * epochs` batches (in this case,148400 batches). You may need to use the repeat() function when building your dataset.
WARNING:tensorflow:Your input ran out of data; interrupting training. Make sure that your dataset or generator can generate at least `steps_per_epoch * epochs` batches (in this case,78 batches). You may need to use the repeat() function when building your dataset.

1484/1484 [==============================] - 30s 15ms/step - loss: 7250.9988 - val_loss: 13595.9355
C:\Users\Tristan\anaconda3\envs\tf2\lib\site-packages\tensorflow\python\keras\engine\training.py:2325: UserWarning: `Model.state_updates` will be removed in a future version. This property should not be used in TensorFlow 2.0,as `updates` are applied automatically.
  warnings.warn('`Model.state_updates` will be removed in a future version. '
2021-01-05 15:37:04.425018: W tensorflow/python/util/util.cc:348] Sets are not currently considered sequences,but this may change in the future,so consider avoiding using them.
C:\Users\Tristan\anaconda3\envs\tf2\lib\site-packages\tensorflow\python\keras\engine\base_layer.py:1402: UserWarning: `layer.updates` will be removed in a future version. This property should not be used in TensorFlow 2.0,as `updates` are applied automatically.
  warnings.warn('`layer.updates` will be removed in a future version. '
WARNING:tensorflow:FOR KERAS USERS: The object that you are saving contains one or more Keras models or layers. If you are loading the SavedModel with `tf.keras.models.load_model`,continue reading (otherwise,you may ignore the following instructions). Please change your code to save with `tf.keras.models.save_model` or `model.save`,and confirm that the file "keras.metadata" exists in the export directory. In the future,Keras will only load the SavedModels that have this file. In other words,`tf.saved_model.save` will no longer write SavedModels that can be recovered as Keras models (this will apply in TF 2.5).

FOR DEVS: If you are overwriting _tracking_metadata in your class,this property has been used to save metadata in the SavedModel. The metadta field will be deprecated soon,so please move the metadata to a different file.
libpng warning: iCCP: known incorrect sRGB profile

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-