Skip to content

Commit

Permalink
style: reformatted the python files of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
ksakmann committed Feb 23, 2017
1 parent 18e1c68 commit 85b8814
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 105 deletions.
29 changes: 0 additions & 29 deletions HOG_Classify.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@

# coding: utf-8

# In[1]:

import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -20,8 +15,6 @@
from lesson_functions import *


# In[2]:

# Load the training validation and test data
data_file = 'data.p'
with open(data_file, mode='rb') as f:
Expand All @@ -34,8 +27,6 @@
notcars_test = data['notcars_test']


# In[3]:

#helper function to extract features from files

def get_features(files, color_space='RGB', spatial_size=(32, 32),
Expand All @@ -55,8 +46,6 @@ def get_features(files, color_space='RGB', spatial_size=(32, 32),
return features


# In[4]:

color_space = 'HLS' # Can be RGB, HSV, LUV, HLS, YUV, YCrCb
spatial_size = (16, 16)
hist_bins = 32
Expand Down Expand Up @@ -86,8 +75,6 @@ def get_features(files, color_space='RGB', spatial_size=(32, 32),
print(round(t2-t, 2), 'Seconds to extract HOG,spatial and color features...')


# In[5]:

# Create an array stack of feature vectors
X = np.vstack((cars_train_feat,cars_val_feat,cars_test_feat,
notcars_train_feat,notcars_val_feat,notcars_test_feat)).astype(np.float64)
Expand All @@ -97,8 +84,6 @@ def get_features(files, color_space='RGB', spatial_size=(32, 32),
scaled_X = X_scaler.transform(X)


# In[6]:

cars_ntrain=len(cars_train_feat)
cars_nval=len(cars_val_feat)
cars_ntest=len(cars_test_feat)
Expand Down Expand Up @@ -128,8 +113,6 @@ def get_features(files, color_space='RGB', spatial_size=(32, 32),
X_test,y_test = shuffle(X_test,y_test,random_state=42)


# In[7]:

print('Using:',orient,'orientations',pix_per_cell,'pixels per cell and', cell_per_block,'cells per block')
print('Feature vector length:', len(X_train[0]))
# Use a linear SVC
Expand All @@ -156,8 +139,6 @@ def get_features(files, color_space='RGB', spatial_size=(32, 32),
print(round(t2-t, 5), 'Seconds to predict', n_predict,'labels with SVC')


# In[18]:

font_size=15
f, axarr = plt.subplots(4, 7,figsize=(20,10))
f.subplots_adjust(hspace=0.2, wspace=0.05)
Expand Down Expand Up @@ -227,8 +208,6 @@ def get_features(files, color_space='RGB', spatial_size=(32, 32),
#plt.savefig('./images/HOG_features_YCrCb.png')


# In[9]:

# plot false positives/negatives
font_size=15
preds = svc.predict(cars_val_feat)
Expand All @@ -253,8 +232,6 @@ def get_features(files, color_space='RGB', spatial_size=(32, 32),
#plt.savefig('./images/false_negatives.png')


# In[10]:

fig, axes = plt.subplots(2,10,figsize=(20,5))
fig.subplots_adjust(hspace=0.2, wspace=0.05)

Expand All @@ -275,8 +252,6 @@ def get_features(files, color_space='RGB', spatial_size=(32, 32),
#plt.savefig('./images/false_positives.png')


# In[11]:

# Save the data for easy access
pickle_file = 'ProcessedData.p'
print('Saving data to pickle file...')
Expand Down Expand Up @@ -325,7 +300,3 @@ def get_features(files, color_space='RGB', spatial_size=(32, 32),
print('Data cached in pickle file.')


# In[ ]:



32 changes: 0 additions & 32 deletions exploration.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@

# coding: utf-8

# In[1]:

import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -16,8 +11,6 @@
from sklearn.model_selection import train_test_split


# In[2]:

# Loading + training,validation test split
cars0 = glob.glob('./vehicles/GTI_Far/*.png')
cars1 = glob.glob('./vehicles/GTI_MiddleClose/*.png')
Expand Down Expand Up @@ -46,13 +39,6 @@
notcars_test = notcars1[L2[5]:]


# In[3]:

L1,L2


# In[4]:

print('Number of samples in cars training set: ', len(cars_train))
print('Number of samples in notcars training set: ', len(notcars_train))

Expand All @@ -63,10 +49,6 @@
print('Number of samples in notcars test set: ',len(notcars_test))


# **Conclusion: The two classes are more or less balanced.**

# In[5]:

# Save the data for easy access
pickle_file = 'data.p'
print('Saving data to pickle file...')
Expand All @@ -89,8 +71,6 @@
print('Data cached in pickle file.')


# In[6]:

data_file = 'data.p'
with open(data_file, mode='rb') as f:
data = pickle.load(f)
Expand All @@ -101,17 +81,11 @@
cars_test = data['cars_test']
notcars_test = data['notcars_test']


# In[7]:

i=22
a_car = plt.imread(cars_train[i])
not_a_car = plt.imread(notcars_train[i])
cars_train[i],notcars_train[i]


# In[8]:

font_size=30
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(20,10))
ax1.imshow(a_car)
Expand All @@ -123,8 +97,6 @@
plt.show()


# In[9]:

f, (ax1, ax2) = plt.subplots(1, 2, figsize=(20,10))
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(20,10))
ax1.imshow(a_car)
Expand All @@ -136,7 +108,3 @@
plt.savefig('./images/car_notcar.png')


# In[ ]:



Binary file modified images/car_notcar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 0 additions & 44 deletions search_classify.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@

# coding: utf-8

# In[1]:

import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -25,8 +20,6 @@
from scipy.ndimage.measurements import label


# In[2]:

# Load the classifier and parameters
data_file = 'ClassifierData.p'
with open(data_file, mode='rb') as f:
Expand All @@ -46,13 +39,7 @@
hog_feat = data['hog_feat']


# In[3]:

images = sorted(glob.glob('test_images/out*.png'))
#images


# In[4]:

#image = mpimg.imread('bbox-example-image.png')
# Uncomment the following line if you extracted training
Expand All @@ -64,17 +51,6 @@ def search_all_scales(image):

hot_windows = []
all_windows = []
#Y_start_stop =[[300,460]]
#XY_window = [(150,150)]
#X_start_stop =[[None,None]]
#X_start_stop =[[None,None],[None,None],[None,None]]
#Y_start_stop =[[390,440],[400,560],[400,560]]
#XY_window = [(80,80),(110,110),(130,130)]

X_start_stop =[[None,None],[None,None]]
Y_start_stop =[[390,470],[390,500]]
XY_window = [(64,64),(110,110)]
XY_overlap=[(0.75, 0.75),(0.75, 0.75)]

X_start_stop =[[None,None],[None,None],[None,None],[None,None]]
w0,w1,w2,w3 = 240,180,120,70
Expand Down Expand Up @@ -102,8 +78,6 @@ def search_all_scales(image):
return hot_windows,all_windows


# In[5]:

for file in images[43:44]:
image = mpimg.imread(file)
#image = image.astype(np.float32)/255
Expand Down Expand Up @@ -143,8 +117,6 @@ def search_all_scales(image):
#plt.savefig('images/sliding_windows.png')


# In[6]:

file0 = images[10]
file1 = images[70]
file2 = images[83]
Expand All @@ -168,12 +140,10 @@ def search_all_scales(image):
ax.set_yticks([])

plt.show()
#plt.savefig('images/detection_example.png')


# ## Video Pipeline

# In[7]:

# Define a class to receive the characteristics of bounding box detections
class BoundingBoxes:
Expand Down Expand Up @@ -228,7 +198,6 @@ def apply_threshold(heatmap, threshold):
return heatmap


# In[8]:

images = sorted(glob.glob('./heatmap/*.png'))
boxes = BoundingBoxes(n=6)
Expand Down Expand Up @@ -280,15 +249,12 @@ def apply_threshold(heatmap, threshold):
plt.show()


# In[9]:

labels = label(heatmap)
print(labels[1], 'cars found')
plt.imshow(labels[0], cmap='gray')
plt.show()


# In[10]:

def draw_labeled_bboxes(img, labels):
# Iterate through all detected cars
Expand All @@ -314,7 +280,6 @@ def draw_labeled_bboxes(img, labels):
plt.show()


# In[13]:

boxes = BoundingBoxes(n=30)

Expand All @@ -334,7 +299,6 @@ def process_image(image):
return window_image


# In[14]:

out_dir='./output_images/'
inpfile='project_video.mp4'
Expand All @@ -346,8 +310,6 @@ def process_image(image):

# ## Images for Readme

# In[ ]:

heatmap_images = sorted(glob.glob('./heatmap/*.png'))
boxes = BoundingBoxes(n=6)

Expand Down Expand Up @@ -393,17 +355,13 @@ def process_image(image):
plt.savefig('images/heatmap.png')


# In[ ]:

plt.figure()
labels = label(final_heatmap)
print(labels[1], 'cars found')
plt.imshow(labels[0], cmap='gray')
plt.savefig('images/labels.png')


# In[ ]:

# Read in the last image above
image = mpimg.imread(image_seq[-1])
# Draw bounding boxes on a copy of the image
Expand All @@ -416,7 +374,5 @@ def process_image(image):
plt.savefig('images/bounding_boxes.png')


# In[ ]:



0 comments on commit 85b8814

Please sign in to comment.