deffunc(input_file):classes = ['D00', 'D10', 'D20', 'D40']alt_names = {'D00': 'lateral_crack', 'D10': 'linear_cracks', 'D20': 'aligator_crakcs', 'D40': 'potholes'} # initialize a list of colors to represent each possible class labelnp.random.seed(42)COLORS = np.random.randint(0, 255, size=(len(classes), 3),dtype="uint8") # derive the paths to the YOLO weights and model configurationweightsPath = "/content/drive/MyDrive/yolo/yolo-obj_final.weights"configPath = "/content/yolov3.cfg" # load our YOLO object detector trained on COCO dataset (80 classes) # and determine only the *output* layer names that we need from YOLO #print("[INFO] loading YOLO from disk...")net = cv2.dnn.readNetFromDarknet(configPath, weightsPath)ln = net.getLayerNames()ln = [ln[i[0] - 1] for i in net.getUnconnectedOutLayers()] # read the next frame from the fileframe = cv2.imread(input_file)(H,W) = frame.shape[:2] # construct a blob from the input frame and then perform a forward # pass of the YOLO object detector, giving us our bounding boxes # and associated probabilitiesblob = cv2.dnn.blobFromImage(frame, 1 / 255.0, (416, 416),swapRB=True, crop=False)net.setInput(blob)start = time.time()layerOutputs = net.forward(ln)end = time.time() # initialize our lists of detected bounding boxes, confidences, # and class IDs, respectivelyboxes = []confidences = []classIDs = [] # loop over each of the layer outputsforoutput in layerOutputs: # loop over each of the detectionsfordetection in output: # extract the class ID and confidence (i.e., probability) # of the current object detectionscores = detection[5:]classID = np.argmax(scores)confidence = scores[classID] # filter out weak predictions by ensuring the detected # probability is greater than the minimum probabilityifconfidence > 0.3: # scale the bounding box coordinates back relative to # the size of the image, keeping in mind that YOLO # actually returns the center (x, y)-coordinates of # the bounding box followed by the boxes' width and # heightbox = detection[0:4] * np.array([W, H, W, H])(centerX,centerY, width, height) = box.astype("int") # use the center (x, y)-coordinates to derive the top # and and left corner of the bounding boxx = int(centerX - (width / 2))y = int(centerY - (height / 2)) # update our list of bounding box coordinates, # confidences, and class IDsboxes.append([x,y, int(width), int(height)])confidences.append(float(confidence))classIDs.append(classID) # apply non-maxima suppression to suppress weak, overlapping # bounding boxesidxs = cv2.dnn.NMSBoxes(boxes, confidences, 0.3,0.25) # ensure at least one detection existsiflen(idxs) > 0: # loop over the indexes we are keepingfori in idxs.flatten(): # extract the bounding box coordinates(x,y) = (boxes[i][0], boxes[i][1])(w,h) = (boxes[i][2], boxes[i][3]) # draw a bounding box rectangle and label on the framecolor = [int(c) for c in COLORS[classIDs[i]]]cv2.rectangle(frame,(x, y), (x + w, y + h), color, 2)label = classes[classIDs[i]]text = "{}: {:.4f}".format(alt_names[label],confidences[i])cv2.putText(frame,text, (x, y - 5),cv2.FONT_HERSHEY_SIMPLEX,0.5, color, 2) cv2_imshow(frame)