JohnleeHIT / Brats2019

[BrainLes2019] Multi-step cascaded network for brain tumor segmentations (tensorflow)
https://arxiv.org/abs/1908.05887
MIT License
95 stars 24 forks source link

why is there a problem "AttributeError: 'BatchGenerator' object has no attribute 'next'? #13

Closed 675492062 closed 4 years ago

675492062 commented 4 years ago

Traceback (most recent call last): File "/home/xwl/Brats2019/src/main.py", line 72, in tf.app.run() File "/home/anaconda3/envs/tf112/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run _sys.exit(main(argv)) File "/home/xwl/Brats2019/src/main.py", line 47, in main model.train() # training process File "/home/xwl/Brats2019/src/operations.py", line 279, in train batch_img, batch_img2, batch_label, batch_label_stage2, batch_label_stage3 = next(data_generator) File "/home/anaconda3/envs/tf112/lib/python3.6/site-packages/keras_preprocessing/image.py", line 1526, in next return self.next(*args, **kwargs) AttributeError: 'BatchGenerator' object has no attribute 'next' //////////////////////////////////////////////////////////////////////////////////////////////////////////// I have tried to change the codes from "batch_img, batch_img2, batch_label, batch_label_stage2, batch_label_stage3 = next(data_generator)"
to batch_img, batch_img2, batch_label, batch_label_stage2, batch_label_stage3 = data_generator.next() But This error still exists!

        batch_img, batch_img2, batch_label, batch_label_stage2, batch_label_stage3 = next(data_generator)
JohnleeHIT commented 4 years ago

As a hint told: "BatchGenerator' object has no attribute 'next'" BatchGenerator is a iterator, we can get the data by calling next(BatchGenerator ) but not BatchGenerator.next()

675492062 commented 4 years ago

As a hint told: "BatchGenerator' object has no attribute 'next'" BatchGenerator is a iterator, we can get the data by calling next(BatchGenerator ) but not BatchGenerator.next()

这两种都试了,都是报这个错误。我严重怀疑是不是tensorflow版本问题,我用的1.12

675492062 commented 4 years ago

I have solved this problem! adding the next method in class BatchGenerator(Iterator): def next(self): """For python 2.x.

Returns

        The next batch.
    """
    with self.lock:
        index_array = next(self.index_generator)
    # The transformation of images is not under thread lock
    # so it can be done in parallel
    return self._get_batches_of_transformed_samples(index_array)