You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 7, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 7, 2026. It is now read-only.
when running the following code in TrainModel.ipynb an error arose:
[sample_batch_train_data, sample_batch_test_data] = next(train_generator)
the error is:
ValueError Traceback (most recent call last)
in ()
24 plt.show()
25
---> 26 [sample_batch_train_data, sample_batch_test_data] = next(train_generator)
27 for i in range(0, 3, 1):
28 draw_image_with_label(sample_batch_train_data[0][i], sample_batch_test_data[i])
D:\tools\anaconda\envs\ND-P2-python3\lib\site-packages\keras\preprocessing\image.py in next(self, *args, **kwargs)
735
736 def next(self, *args, **kwargs):
--> 737 return self.next(*args, **kwargs)
738
739
~\AutonomousDrivingCookbook\AirSimE2EDeepLearning\Generator.py in next(self)
240 # so it can be done in parallel
241
--> 242 return self.__get_indexes(index_array)
243
244 def __get_indexes(self, index_array):
~\AutonomousDrivingCookbook\AirSimE2EDeepLearning\Generator.py in __get_indexes(self, index_array)
243
244 def __get_indexes(self, index_array):
--> 245 index_array = sorted(index_array)
246 if self.x_prev_states is not None:
247 batch_x_images = np.zeros(tuple([self.batch_size]+ list(self.x_images.shape)[1:]),
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
please note that I have not added or deleted any code in Generator.py file. And I have generated datasets successfully in step 0.
I do not know why this error arose, it makes no sense that sorted() function made this error.
Can you give me the version of the following packages that you are using (this can be obtained by running pip freeze), as well as the python version you are running? For reference, here are the versions I am using:
numpy (1.13.3)
pandas (0.20.3)
keras (2.1.2)
tensorflow-gpu (1.1.0)
Aditya Sharma (@adshar) has run into the same issue in the past, and solved it by upgrading Keras to the latest (pip install --upgrade Keras)
Please let me know if this solves your problem and we can close this issue.
Mitchell Spryn (@mitchellspryn) Thanks for responding! I have fixed the bug by myself. When I use debug mode in jupyter notebook, I found that the object index_array mentioned in the error message is a tuple and with a array in it. This made sense that the index_array object could not be sorted. As showed below:
So I add a line in generator.py file, to get the first element(the array) of index_array and resigned it to index_array again. The problem solved.
But how did adshar make it work without doing what I did? I mean, he only updated the version of keras. I am quite confused.
Our generator is an extension of the Keras ImageDataGenerator(). In older versions of Keras, next() returns a tuple, as you discovered. In the later versions, next() only returns the masking index (the first item in the tuple). So, in addition to your workaround, updating Keras will solve this problem.
Thanks for confirming that it works! I'll close the issue for now.
when running the following code in TrainModel.ipynb an error arose:
[sample_batch_train_data, sample_batch_test_data] = next(train_generator)
the error is:
please note that I have not added or deleted any code in Generator.py file. And I have generated datasets successfully in step 0.
I do not know why this error arose, it makes no sense that sorted() function made this error.