llSourcell / How_to_simulate_a_self_driving_car

This is the code for "How to Simulate a Self-Driving Car" by Siraj Raval on Youtube
430 stars 306 forks source link

Error in random_shadow method in Utils.py Index Error line no 101 #16

Open sskadit opened 7 years ago

sskadit commented 7 years ago

Hello Siraj thanks a lot for wonderful video but there is an error coming while training the dataset.

# Using TensorFlow backend.
------------------------------
Parameters
------------------------------
learning_rate        := 0.0001
keep_prob            := 0.5
nb_epoch             := 10
save_best_only       := True
samples_per_epoch    := 20000
test_size            := 0.2
batch_size           := 40
data_dir             := data
------------------------------
model.py:66: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(24, (5, 5), activation="elu", strides=(2, 2))`
  model.add(Conv2D(24, 5, 5, activation='elu', subsample=(2, 2)))
model.py:67: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(36, (5, 5), activation="elu", strides=(2, 2))`
  model.add(Conv2D(36, 5, 5, activation='elu', subsample=(2, 2)))
model.py:68: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(48, (5, 5), activation="elu", strides=(2, 2))`
  model.add(Conv2D(48, 5, 5, activation='elu', subsample=(2, 2)))
model.py:69: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (3, 3), activation="elu")`
  model.add(Conv2D(64, 3, 3, activation='elu'))
model.py:70: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(64, (3, 3), activation="elu")`
  model.add(Conv2D(64, 3, 3, activation='elu'))
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
lambda_1 (Lambda)            (None, 66, 200, 3)        0         
_________________________________________________________________
conv2d_1 (Conv2D)            (None, 31, 98, 24)        1824      
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 14, 47, 36)        21636     
_________________________________________________________________
conv2d_3 (Conv2D)            (None, 5, 22, 48)         43248     
_________________________________________________________________
conv2d_4 (Conv2D)            (None, 3, 20, 64)         27712     
_________________________________________________________________
conv2d_5 (Conv2D)            (None, 1, 18, 64)         36928     
_________________________________________________________________
dropout_1 (Dropout)          (None, 1, 18, 64)         0         
_________________________________________________________________
flatten_1 (Flatten)          (None, 1152)              0         
_________________________________________________________________
dense_1 (Dense)              (None, 100)               115300    
_________________________________________________________________
dense_2 (Dense)              (None, 50)                5050      
_________________________________________________________________
dense_3 (Dense)              (None, 10)                510       
_________________________________________________________________
dense_4 (Dense)              (None, 1)                 11        
=================================================================
Total params: 252,219
Trainable params: 252,219
Non-trainable params: 0
_________________________________________________________________
model.py:120: UserWarning: The semantics of the Keras 2 argument `steps_per_epoch` is not the same as the Keras 1 argument `samples_per_epoch`. `steps_per_epoch` is the number of batches to draw from the generator at each epoch. Basically steps_per_epoch = samples_per_epoch/batch_size. Similarly `nb_val_samples`->`validation_steps` and `val_samples`->`steps` arguments have changed. Update your method calls accordingly.
  verbose=2)
model.py:120: UserWarning: Update your `fit_generator` call to the Keras 2 API: `fit_generator(<generator..., 20000, 10, validation_data=<generator..., max_queue_size=1, verbose=2, validation_steps=956, callbacks=[<keras.ca...)`
  verbose=2)
Epoch 1/10
mask is here [[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/sskadit/Desktop/neuralnetworks/neuralnetworks/lib/python3.4/site-packages/keras/utils/data_utils.py", line 568, in data_generator_task
    generator_output = next(self._generator)
  File "/Users/sskadit/Desktop/neuralnetworks/neuralnetworks/Car/utils.py", line 150, in batch_generator
    image, steering_angle = augument(data_dir, center, left, right, steering_angle)
  File "/Users/sskadit/Desktop/neuralnetworks/neuralnetworks/Car/utils.py", line 132, in augument
    image = random_shadow(image)
  File "/Users/sskadit/Desktop/neuralnetworks/neuralnetworks/Car/utils.py", line 101, in random_shadow
    mask[(ym - y1) * (x2 - x1) - (y2 - y1) * (xm - x1) > 0] = 1
IndexError: boolean index did not match indexed array along dimension 0; dimension is 160 but corresponding boolean dimension is 66

Traceback (most recent call last):
  File "model.py", line 163, in <module>
    main()
  File "model.py", line 159, in main
    train_model(model, args, *data)
  File "model.py", line 120, in train_model
    verbose=2)
  File "/Users/sskadit/Desktop/neuralnetworks/neuralnetworks/lib/python3.4/site-packages/keras/legacy/interfaces.py", line 87, in wrapper
    return func(*args, **kwargs)
  File "/Users/sskadit/Desktop/neuralnetworks/neuralnetworks/lib/python3.4/site-packages/keras/models.py", line 1121, in fit_generator
    initial_epoch=initial_epoch)
  File "/Users/sskadit/Desktop/neuralnetworks/neuralnetworks/lib/python3.4/site-packages/keras/legacy/interfaces.py", line 87, in wrapper
    return func(*args, **kwargs)
  File "/Users/sskadit/Desktop/neuralnetworks/neuralnetworks/lib/python3.4/site-packages/keras/engine/training.py", line 2011, in fit_generator
    generator_output = next(output_generator)
StopIteration
Duskfall commented 7 years ago

Same here

Duskfall commented 7 years ago

Fixed it with np.where: mask[np.where((ym - y1) * (x2 - x1) - (y2 - y1) * (xm - x1) > 0)] = 1

ihteshamraza commented 6 years ago

hy, so you were able to run the project? i'm getting an error that says it was unable to create model-001.h5 (trained model). i have opened an issue regarding this as well. can you help? after first epoch is complete and, it says it was unable to create the file. no such file or directory

PapaBravo87 commented 5 years ago

same here

Fixed it with np.where: mask[np.where((ym - y1) (x2 - x1) - (y2 - y1) (xm - x1) > 0)] = 1

mask[np.where(ym - y1) (x2 - x1) - (y2 - y1) (xm - x1) > 0] = 1 TypeError: can't multiply sequence by non-int of type 'float'

nh17937 commented 5 years ago

My colleague had this problem and this is because the images generated by the Udacity simulator now have different sizes. In the utils.py the authors of this repo set the image height and width on the 6th line. In the code it is 66 and 200. But the images that are generated are now 160X320, so just change this in the utils.py.