keras predict_generator is shuffling its output when using a keras.utils.Sequence

后端 未结 1 1233
春和景丽
春和景丽 2021-01-13 18:17

I am using keras to build a model that inputs 720x1280 images and outputs a value.

I am having a problem with keras.models.Sequential.predict_generator

1条回答
  •  迷失自我
    2021-01-13 18:27

    predict_generator was not shuffling my predictions, after all. The problem was with the __getitem__ method. For instance, usingn_batch=32, the method would yield values from 1 to 32, then from 2 to 33 and so forth, instead of from 1 to 32, 33 to 64, etc.

    Changing the method as follows solves the problem

     def __getitem__(self, idx):
        # batch_x is a numpy.ndarray
        idx_min = idx*self.batch_size
        idx_max = min(idx_min + self.batch_size, self.n)
        batch_x = (
                self.images[idx_min:idx_max]
                .concatenate()
                .reshape(self.batch_size, 720, 1280, 1)
                ) 
        batch_y = self.hf[idx_min:idx_max]
    

    0 讨论(0)
提交回复
热议问题