如何理解predict_generator中的步骤参数?

时间:2017-06-05 13:13:20

标签: python generator keras predict

我对predict_generator中的steps参数的作用不太确定,我理解的是步骤表示生成器生成的数据量,但有人否认我的答案,有人确认我的答案 我通过练习仍然无法找到正确的答案,我的方式是这样,我使用openslide来读取5000x5000大小的图像,每个产生一个小地图100x100来预测正常我可以读取2500 100x100图片的大小,但是当我设置步数= 2500是错误的

这是代码:

# coding=utf-8
from __future__ import division
from keras.models import load_model
import openslide
import numpy as np
import Get_file_name
import  generator
import matplotlib.pyplot as plt

def predict_model(img):
    model = load_model(Get_file_name.model_path[0])
    y= model.predict_generator(generator.pre_gen(img),steps=30)
    print(y)

predict_model("cats_and_dogs_5")

这是错误的:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 612, in data_generator_task
generator_output = next(self._generator)

StopIteration异常

Traceback (most recent call last):
File "/home/zh/视频/MitosisDetection/mitosisDetection/predict.py", line 17, in <module>
predict_model("cats_and_dogs_5")
File "/home/zh/视频/MitosisDetection/mitosisDetection/predict.py", line 12, in predict_model
y= model.predict_generator(generator.pre_gen(img),steps=2500)
File "/usr/local/lib/python3.5/dist-packages/keras/legacy/interfaces.py", line 88, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/keras/models.py", line 1183, in predict_generator
verbose=verbose)
File "/usr/local/lib/python3.5/dist-packages/keras/legacy/interfaces.py", line 88, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 2108, in predict_generator
outs = self.predict_on_batch(x)
File "/usr/local/lib/python3.5/dist-packages/keras/engine/training.py", line 1696, in predict_on_batch
outputs = self.predict_function(ins)
File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 2229, in __call__
feed_dict=feed_dict)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 778, in run
run_metadata_ptr)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 961, in _run
% (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape () for Tensor 'conv2d_1_input:0', which has shape '(?, 64, 64, 3)'

Process finished with exit code 1

如果steps表示我的生成器生成的数据量,那么为什么我设置steps = 2500错误?如果步骤不代表生成器生成的数据量,那么我该怎么办?如何设置生成器生成的数据量? 请上帝更多的建议,我今天在身边,很多人都不明白这件事!

0 个答案:

没有答案