Question: # Install Essential Libraries ! pip install ultralytics import numpy as np # linear algebra import pandas as pd # data processing, CSV file I

# Install Essential Libraries
!pip install ultralytics
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
import os
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
os.path.join(dirname, filename)
from google.colab import drive
# Mount Google Drive
drive.mount('/content/drive')
# Example folder path in Google Drive
Drowsy='/content/drive/My Drive/DDD/Drowsy/Drowsy'
Non_Drowsy='/content/drive/My Drive/DDD/NonDrowsy/NonDrowsy'
# List all files in the folder
Path1= os.listdir(Drowsy)
Path2= os.listdir(Non_Drowsy)
filepaths =[]
labels =[]
for file in drowsy_files:
filepath = os.path.join(Drowsy, file)
filepaths.append(filepath)
labels.append('drowsy')
# Iterate through non-drowsy images and add file paths and labels
for file in non_drowsy_files:
filepath = os.path.join(Non_Drowsy, file)
filepaths.append(filepath)
labels.append('non-drowsy')
df = pd.DataFrame({'filepaths': filepaths, 'labels': labels})
# Print the number of images in each category
print(df['labels'].value_counts())
# Print the DataFrame shape
print(df.shape)
# Print a sample of the DataFrame
print(df.sample(10))
import os
import pandas as pd
dict_list =[Drowsy,Non_Drowsy]
for i, j in enumerate(dict_list):
flist = os.listdir(j)
for f in flist:
fpath = os.path.join(j, f)
filepaths.append(fpath)
if i ==0:
labels.append('Drowsy')
elif i ==1:
labels.append('Non_Drowsy')
Fseries = pd.Series(filepaths, name="filepaths")
Lseries = pd.Series(labels, name="labels")
bc_data = pd.concat([Fseries, Lseries], axis=1)
bc_df = pd.DataFrame(bc_data)
print(bc_df["labels"].value_counts())
print(bc_df.shape)
bc_df.sample(10)
from sklearn.model_selection import train_test_split
# Assuming bc_df is your DataFrame containing the data
train_images, test_images = train_test_split(bc_df, test_size=0.3, random_state=42)
train_set, val_set = train_test_split(bc_df, test_size=0.2, random_state=42)
#Generate batches of tensor image data with real-time data augmentation.
import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
# Assuming you have imported pandas and numpy as well
# Your code for generating image data batches
image_gen = ImageDataGenerator(preprocessing_function=tf.keras.applications.mobilenet_v2.preprocess_input)
train = image_gen.flow_from_dataframe(dataframe=train_set, x_col="filepaths", y_col="labels",
target_size=(244,244),
color_mode='rgb',
class_mode="categorical",
batch_size=32,
shuffle=False)
test = image_gen.flow_from_dataframe(dataframe=test_images, x_col="filepaths", y_col="labels",
target_size=(244,244),
color_mode='rgb',
class_mode="categorical",
batch_size=32,
shuffle=False)
val = image_gen.flow_from_dataframe(dataframe=val_set, x_col="filepaths", y_col="labels",
target_size=(244,244),
color_mode='rgb',
class_mode="categorical",
batch_size=32,
shuffle=False)
classes=list(train.class_indices.keys())
print (classes)
import matplotlib.pyplot as plt
import numpy as np
def bc_images(image_gen):
images, labels = next(image_gen) # get a sample batch from the generator
plt.figure(figsize=(20,20))
length = len(labels)
if length <25:
r = length
else:
r =25
for i in range(r):
plt.subplot(5,5, i +1)
image =(images[i]+1)/2 # scale images between 0 and 1
plt.imshow(image)
plt.title(np.argmax(labels[i]), color="green", fontsize=16)
plt.axis('off')
plt.show()
bc_images(train)
from ultralytics import YOLO
import PIL
from PIL import Image
from IPython.display import display
import os
import pathlib
model = YOLO("yolov8m.pt")
results=model.predict(source="/content/drive/My Drive/DDD/Drowsy/Drowsy/X1346.png",
save=True, conf=0.2,iou=0.5)
result = results[0]
box = result.boxes[0]
for result in results:
boxes = result.boxes # Boxes object for bbox outputs
masks = result.masks # Masks object for segmentation masks outputs
probs =
can you give the driver's drowsiness detection using YOLOv8

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!