Experiment 8
Experiment 8
Procedure
Program Coding
Data Manipulation
import numpy as np
import pandas as pd
# Visualization/Image Processing
import cv2
import matplotlib.pyplot as plt
# Machine Learning
import tensorflow as tf
from tensorflow.keras.layers import Conv2D, Input, BatchNormalization, Flatten, MaxPool2D,
Dense
# Other
from pathlib import Path
train_path = Path("car_detection/data/training_images")
test_path = Path("car_detection/data/testing_images")
if len(pred_coords) == 4:
xmin, ymin, xmax, ymax = pred_coords
img = cv2.rectangle(img, (int(xmin), int(ymin)), (int(xmax), int(ymax)), (255, 0, 0), 3)
plt.imshow(img)
plt.xticks([])
plt.yticks([])
display_image_from_file("vid_4_10520.jpg")
display_grid()
def data_generator(df=train, batch_size=16, path=train_path):
while True:
images = np.zeros((batch_size, 380, 676, 3))
bounding_box_coords = np.zeros((batch_size, 4))
for i in range(batch_size):
rand_index = np.random.randint(0, train.shape[0])
row = df.loc[rand_index, :]
images[i] = cv2.imread(str(train_path/row.image)) / 255.
bounding_box_coords[i] = np.array([row.xmin, row.ymin, row.xmax, row.ymax])
OUTPUT