Opencv python object detection (wandb nontype error)

import cv2 as cv
import numpy as np
from wandb import Classes

# load yolo
net = cv.dnn.readNet("D:\OPEN CV\YOLOV object detection\yolov3.weights",
                     "D:\OPEN CV\YOLOV object detection\yolov3.cfg")
clasees = []
with open("coco.names", 'r') as f:
    classes = [line.strip() for line in f.readlines()]
# print(classes)
layer_name = net.getLayerNames()
output_layer = [layer_name[i - 1] for i in net.getUnconnectedOutLayers()]
colors = np.random.uniform(0, 255, size=(len(classes), 3))

# Load Image
img = cv.imread("D:/OPEN CV/YOLOV object detection/room_ser.jpg")
img = cv.resize(img, None, fx=0.4, fy=0.4)
height, width, channel = img.shape

# Detect Objects
blob = cv.dnn.blobFromImage(
    img, 0.00392, (416, 416), (0, 0, 0), True, crop=False)
net.setInput(blob)
outs = net.forward(output_layer)
# print(outs)

# Showing Information on the screen
class_ids = []
confidences = []
boxes = []
for out in outs:
    for detection in out:
        scores = detection[5:]
        class_id = np.argmax(scores)
        confidence = scores[class_id]
        if confidence > 0.5:
            # Object detection
            center_x = int(detection[0] * width)
            center_y = int(detection[1] * height)
            w = int(detection[2] * width)
            h = int(detection[3] * height)
            # cv.circle(img, (center_x, center_y), 10, (0, 255, 0), 2 )
            # Reactangle Cordinate
            x = int(center_x - w/2)
            y = int(center_y - h/2)
            boxes.append([x, y, w, h])
            confidences.append(float(confidence))
            class_ids.append(class_id)

# print(len(boxes))
# number_object_detection = len(boxes)

indexes = cv.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)
print(indexes)

font = cv.FONT_HERSHEY_PLAIN
for i in range(len(boxes)):
    if i in indexes:
        x, y, w, h = boxes[i]
        label = str(classes[class_ids[i]])
        # print(label)
        color = colors[i]
        cv.rectangle(img, (x, y), (x + w, y + h), color, 2)
        cv.putText(img, label, (x, y + 30), font, 3, color, 3)

cv.imshow("IMG", img)
cv.waitKey(0)
cv.destroyAllWindows()

wandb nontype error

Please post the traceback.

Traceback (most recent call last):
File “C:\Users\asus\Desktop\YOLO-object-detection-using-Opencv-with-Python-main\yolo_object_detection.py”, line 3, in
from wandb import Classes
File “C:\Users\asus\AppData\Local\Programs\Python\Python311\Lib\site-packages\wandb_init_.py”, line 26, in
from wandb import sdk as wandb_sdk
File “C:\Users\asus\AppData\Local\Programs\Python\Python311\Lib\site-packages\wandb\sdk_init_.py”, line 9, in
from .wandb_init import _attach, init # noqa: F401
File “C:\Users\asus\AppData\Local\Programs\Python\Python311\Lib\site-packages\wandb\sdk\wandb_init.py”, line 30, in
from . import wandb_login, wandb_setup
File “C:\Users\asus\AppData\Local\Programs\Python\Python311\Lib\site-packages\wandb\sdk\wandb_login.py”, line 25, in
from .wandb_settings import Settings, Source
File “C:\Users\asus\AppData\Local\Programs\Python\Python311\Lib\site-packages\wandb\sdk\wandb_settings.py”, line 39, in
from wandb.sdk.wandb_setup import _EarlyLogger
File “C:\Users\asus\AppData\Local\Programs\Python\Python311\Lib\site-packages\wandb\sdk\wandb_setup.py”, line 23, in
from .lib import config_util, server, tracelog
File “C:\Users\asus\AppData\Local\Programs\Python\Python311\Lib\site-packages\wandb\sdk\lib\tracelog.py”, line 48, in
stdout_write = sys.stdout.write
AttributeError: ‘NoneType’ object has no attribute ‘write’

import cv2 as cv
import numpy as np
import collections
from collections.abc import MutableSet
collections.MutableSet = collections.abc.MutableSet
from wandb import Classes

# load yolo
net = cv.dnn.readNet("D:\OPEN CV\YOLOV object detection\yolov3.weights",
                     "D:\OPEN CV\YOLOV object detection\yolov3.cfg")
clasees = []
with open("coco.names", 'r') as f:
    classes = [line.strip() for line in f.readlines()]
# print(classes)
layer_name = net.getLayerNames()
output_layer = [layer_name[i - 1] for i in net.getUnconnectedOutLayers()]
colors = np.random.uniform(0, 255, size=(len(classes), 3))

# Load Image
img = cv.imread("D:/OPEN CV/YOLOV object detection/room_ser.jpg")
img = cv.resize(img, None, fx=0.4, fy=0.4)
height, width, channel = img.shape

# Detect Objects
blob = cv.dnn.blobFromImage(
    img, 0.00392, (416, 416), (0, 0, 0), True, crop=False)
net.setInput(blob)
outs = net.forward(output_layer)
# print(outs)

# Showing Information on the screen
class_ids = []
confidences = []
boxes = []
for out in outs:
    for detection in out:
        scores = detection[5:]
        class_id = np.argmax(scores)
        confidence = scores[class_id]
        if confidence > 0.5:
            # Object detection
            center_x = int(detection[0] * width)
            center_y = int(detection[1] * height)
            w = int(detection[2] * width)
            h = int(detection[3] * height)
            # cv.circle(img, (center_x, center_y), 10, (0, 255, 0), 2 )
            # Reactangle Cordinate
            x = int(center_x - w/2)
            y = int(center_y - h/2)
            boxes.append([x, y, w, h])
            confidences.append(float(confidence))
            class_ids.append(class_id)

# print(len(boxes))
# number_object_detection = len(boxes)

indexes = cv.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)
print(indexes)

font = cv.FONT_HERSHEY_PLAIN
for i in range(len(boxes)):
    if i in indexes:
        x, y, w, h = boxes[i]
        label = str(classes[class_ids[i]])
        # print(label)
        color = colors[i]
        cv.rectangle(img, (x, y), (x + w, y + h), color, 2)
        cv.putText(img, label, (x, y + 30), font, 3, color, 3)

cv.imshow("IMG", img)
cv.waitKey(0)
cv.destroyAllWindows()

Traceback (most recent call last):
File “C:\Users\asus\Desktop\YOLO-object-detection-using-Opencv-with-Python-main\yolo_object_detection.py”, line 9, in
net = cv.dnn.readNet(“D:\OPEN CV\YOLOV object detection\yolov3.weights”,
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\darknet\darknet_importer.cpp:210: error: (-212:Parsing error) Failed to open NetParameter file: D:\OPEN CV\YOLOV object detection\yolov3.cfg in function ‘cv::dnn::dnn4_v20220524::readNetFromDarknet’

As it says, it was unable to open or parse D:\OPEN CV\YOLOV object detection\yolov3.cfg.

Does that file exist? If yes, is its contents correct?

it has to be true, it says copy the path or something in the forums, I couldn’t understand it, I have to train it today

sir,i also have the issue…is your problem solved…if yes, please provide that how did you done the process

no i cant solve problem i change my example