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
431 stars 305 forks source link

Training model causes a generator output error #7

Open MLenthousiast opened 7 years ago

MLenthousiast commented 7 years ago

When I execute the command python model.py while the car-behavioral-cloning environment (for CPU version) is activated I get the following error:

Using TensorFlow backend.
------------------------------
Parameters
------------------------------
batch_size           := 40
data_dir             := data
samples_per_epoch    := 20000
learning_rate        := 0.0001
nb_epoch             := 10
test_size            := 0.2
save_best_only       := True
keep_prob            := 0.5
------------------------------
____________________________________________________________________________________________________
Layer (type)                     Output Shape          Param #     Connected to                     
====================================================================================================
lambda_1 (Lambda)                (None, 66, 200, 3)    0           lambda_input_1[0][0]             
____________________________________________________________________________________________________
convolution2d_1 (Convolution2D)  (None, 31, 98, 24)    1824        lambda_1[0][0]                   
____________________________________________________________________________________________________
convolution2d_2 (Convolution2D)  (None, 14, 47, 36)    21636       convolution2d_1[0][0]            
____________________________________________________________________________________________________
convolution2d_3 (Convolution2D)  (None, 5, 22, 48)     43248       convolution2d_2[0][0]            
____________________________________________________________________________________________________
convolution2d_4 (Convolution2D)  (None, 3, 20, 64)     27712       convolution2d_3[0][0]            
____________________________________________________________________________________________________
convolution2d_5 (Convolution2D)  (None, 1, 18, 64)     36928       convolution2d_4[0][0]            
____________________________________________________________________________________________________
dropout_1 (Dropout)              (None, 1, 18, 64)     0           convolution2d_5[0][0]            
____________________________________________________________________________________________________
flatten_1 (Flatten)              (None, 1152)          0           dropout_1[0][0]                  
____________________________________________________________________________________________________
dense_1 (Dense)                  (None, 100)           115300      flatten_1[0][0]                  
____________________________________________________________________________________________________
dense_2 (Dense)                  (None, 50)            5050        dense_1[0][0]                    
____________________________________________________________________________________________________
dense_3 (Dense)                  (None, 10)            510         dense_2[0][0]                    
____________________________________________________________________________________________________
dense_4 (Dense)                  (None, 1)             11          dense_3[0][0]                    
====================================================================================================
Total params: 252,219
Trainable params: 252,219
Non-trainable params: 0
____________________________________________________________________________________________________
Epoch 1/10
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=1)
  File "/home/arthur/anaconda2/envs/car-behavioral-cloning/lib/python3.5/site-packages/keras/models.py", line 924, in fit_generator
    pickle_safe=pickle_safe)
  File "/home/arthur/anaconda2/envs/car-behavioral-cloning/lib/python3.5/site-packages/keras/engine/training.py", line 1481, in fit_generator
    str(generator_output))
ValueError: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None

The only thing I changed about the source code is line 29: data_df = pd.read_csv(os.path.join(args.data_dir, 'driving_log.csv')) into: data_df = pd.read_csv(os.path.join(args.data_dir, 'driving_log.csv'), names=['center', 'left', 'right', 'steering', 'throttle', 'reverse', 'speed']) because I had also an issue with loading the data because the columns weren't named.

Does anyone know how to fix this issue?

grep-rohan commented 7 years ago

Are you sure you made only this change? Because this change should not cause this error. Did you make any changes in utils.py?

MLenthousiast commented 7 years ago

Yes I'm certain, i haven't touched any other file. I double checked it on another pc and got the same problem. But maybe it has something to do with the generated data? I have the data placed in a dir called data which contains a csv file driving_log.csv and another dir called IMG containing all the *.jpg files. I pass the absolute address of this dir along with the command using the -d option.

grep-rohan commented 7 years ago

Another way of naming the data columns is by manually adding them as the first column of the driving_log.csv (Like this). Give this a try and revert model.py back to original.

MLenthousiast commented 7 years ago

Re-cloned and added the headers but still the same error persists..

grep-rohan commented 7 years ago

Copy the data folder in the project's directory and try again without adding the data argument.

MLenthousiast commented 7 years ago

Yeah that is what I did first, but it yields the same error..

grep-rohan commented 7 years ago

Open python console in the project's directory and try reading the images from there. See if the images can be read. Maybe the error is because the images cannot be read.

JohnFodero commented 7 years ago

Hey any luck with this MLenthousiast? I am having the same issue..

grep-rohan commented 7 years ago

Maybe it's because you generated data and shifted the data to another directory. If you do this then you also have to change the image directories in driving_log.csv.

JohnFodero commented 7 years ago

Ah. Makes sense, thanks! Is there a simple way to do this in the .csv?

grep-rohan commented 7 years ago

Use find and replace all in a text editor like sublime text.

Like this: screenshot 1

Abhi001vj commented 7 years ago

We are passing data directory so we have path till data right ,then in the path of images we need only IMG folder...? or do we need the whole path till IMG def load_image(data_dir, image_file): """ Load RGB images from a file """ return mpimg.imread(os.path.join(data_dir, image_file.strip()))

hwlewter commented 7 years ago

I had the same trouble as the Original Poster on the 2nd computer I tried this experiment on. (It worked on the first). I found there is something in the random_shadow function of the utils.py file that the 2nd computer didn't like. I was able to comment out line 131 inside the augument function of utils.py to avoid the error. However, this means the training images don't get the random shadow treatment and lose out on that variable when learning. image

sebasmaltese commented 7 years ago

This is because random_shadow() uses IMAGE_WIDTH and IMAGE_HEIGHT but we haven't cropped the image yet. Add height, width = image.shape[:2] and use those variables instead, just like in random_translate(). Doing this fixed this issue for me.

isaaccorley commented 7 years ago

I was also having this issue. It was due to the below line of code in the random_shadow function in utils.py.

mask[(ym - y1) (x2 - x1) - (y2 - y1) (xm - x1) > 0] = 1

I added the numpy "where" function to this line and everything worked.

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

I believe it's due to an update in numpy. Hope this helped.

neuroai commented 7 years ago

@IsaacCorley Got the same error, and tried the "where" trick, and it worked. Thank you.

robogeekcanada commented 7 years ago

the "where" trick works. Thank you

eng-tsmith commented 7 years ago

The random_shadow() function creates a random shadow for an image of the size (66, 200). The problem is, that we are feeding a non-cropped image (160, 320) into the function at this point. The "where" trick mentioned above may prevent the error, but the logic when creating the shadow is wrong! When using the "where" trick, a shadow in only the top left part of the image (66, 200) will be created.

The first few lines in random_shadow() should be changed to:

height, width = image.shape[:2]
# (x1, y1) and (x2, y2) forms a line
# xm, ym gives all the locations of the image
x1, y1 = int(width * np.random.rand()), 0
x2, y2 = int(width * np.random.rand()), height
xm, ym = np.mgrid[0:height, 0:width]

This way there will be a random shadow over the whole image (160, 320). The image can be cropped and resized at a later point.

satwikmishra commented 6 years ago

Guys , follow all the steps above till eng-tsmith and if you still happen to have a problem ,then ignore it and proceed to the next step i.e , python drive.py model.h5 . This worked for us. Thank you everyone.

robogeekcanada commented 6 years ago

It's true the where trick prevents the error but as explained by eng-tsmith it has unintended consequence. Thank you for pointing it out.

satwikmishra commented 6 years ago

Can't get it to run. Getting errorsTraceback (most recent call last): File "model.py", line 163, in main() File "model.py", line 159, in main train_model(model, args, *data) File "model.py", line 120, in train_model verbose=1) File "D:\Docs\Anaconda3\envs\car-behavioral-cloning\lib\site-packages\keras\models.py", line 924, in fit_generator pickle_safe=pickle_safe)

File "D:\Docs\Anaconda3\envs\car-behavioral-cloning\lib\site-packages\keras\engine\training.py", line 1481, in fit_generator str(generator_output)) ValueError: output of generator should be a tuple (x, y, sample_weight) or (x, y). Found: None

I am getting the same error after doing all necessary changes.