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 IO eg pdreadcsv
# Input data files are available in the readonly input directory
# For example, running this by clicking run or pressing ShiftEnter will list all files under the input directory
import os
for dirname, filenames in oswalkkaggleinput:
for filename in filenames:
ospath.joindirname filename
from google.colab import drive
# Mount Google Drive
drive.mountcontentdrive
# Example folder path in Google Drive
DrowsycontentdriveMy DriveDDDDrowsyDrowsy
NonDrowsycontentdriveMy DriveDDDNonDrowsyNonDrowsy
# List all files in the folder
Path oslistdirDrowsy
Path oslistdirNonDrowsy
filepaths
labels
for file in drowsyfiles:
filepath ospath.joinDrowsy file
filepaths.appendfilepath
labels.appenddrowsy
# Iterate through nondrowsy images and add file paths and labels
for file in nondrowsyfiles:
filepath ospath.joinNonDrowsy, file
filepaths.appendfilepath
labels.appendnondrowsy'
df pdDataFramefilepaths: filepaths, 'labels': labels
# Print the number of images in each category
printdflabelsvaluecounts
# Print the DataFrame shape
printdfshape
# Print a sample of the DataFrame
printdfsample
import os
import pandas as pd
dictlist DrowsyNonDrowsy
for i j in enumeratedictlist:
flist oslistdirj
for f in flist:
fpath ospath.joinj f
filepaths.appendfpath
if i :
labels.appendDrowsy
elif i :
labels.appendNonDrowsy'
Fseries pdSeriesfilepaths name"filepaths"
Lseries pdSerieslabels name"labels"
bcdata pdconcatFseries Lseries axis
bcdf pdDataFramebcdata
printbcdflabelsvaluecounts
printbcdfshape
bcdfsample
from sklearn.modelselection import traintestsplit
# Assuming bcdf is your DataFrame containing the data
trainimages, testimages traintestsplitbcdf testsize randomstate
trainset, valset traintestsplitbcdf testsize randomstate
#Generate batches of tensor image data with realtime 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
imagegen ImageDataGeneratorpreprocessingfunctiontfkeras.applications.mobilenetvpreprocessinput
train imagegen.flowfromdataframedataframetrainset, xcol"filepaths", ycol"labels",
targetsize
colormodergb
classmode"categorical",
batchsize
shuffleFalse
test imagegen.flowfromdataframedataframetestimages, xcol"filepaths", ycol"labels",
targetsize
colormodergb
classmode"categorical",
batchsize
shuffleFalse
val imagegen.flowfromdataframedataframevalset, xcol"filepaths", ycol"labels",
targetsize
colormodergb
classmode"categorical",
batchsize
shuffleFalse
classeslisttrainclassindices.keys
print classes
import matplotlib.pyplot as plt
import numpy as np
def bcimagesimagegen:
images, labels nextimagegen # get a sample batch from the generator
pltfigurefigsize
length lenlabels
if length :
r length
else:
r
for i in ranger:
pltsubplot i
image imagesi # scale images between and
pltimshowimage
plttitlenpargmaxlabelsi color"green", fontsize
pltaxisoff
pltshow
bcimagestrain
from ultralytics import YOLO
import PIL
from PIL import Image
from IPython.display import display
import os
import pathlib
model YOLOyolovmpt
resultsmodel.predictsourcecontentdriveMy DriveDDDDrowsyDrowsyXpng
saveTrue, confiou
result results
box result.boxes
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 YOLOv
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
