python - 模块“darknet”没有属性“load_network”
问题描述
我正在尝试从 Google Colab 运行 YOLO 的掩码检测代码。但是当我运行我的代码时出现这个错误:
模块“darknet”没有属性“load_network”
知道为什么吗?我确实有我的darknet.py
进口
我使用的代码:
from ctypes import *
import math
import random
import os
import cv2
import numpy as np
import time
import darknet
#OpenCV need the 4 corners
def convertBack(x, y, w, h): #OpenCV uses top left and bottom right
xmin = int(round(x - (w / 2))) #corner of rectangle box as input points
xmax = int(round(x + (w / 2)))
ymin = int(round(y - (h / 2)))
ymax = int(round(y + (h / 2)))
return xmin, ymin, xmax, ymax
# drawing bounding boxes on image from detections
def DrawBBoxes(detections, img, dim, colors): #detections = detected objects, img= image of detected object, dim= dimensions of img
i = 1 #for "array of 6 elements" in detections --> label= detected class name, confidence= accuracy of detection, bbox= contains 4 elements x,y,w,h.
for label, confidence, bbox in detections: #x and y is coordinates of center of bbox, w and h is width and height of bbox
x, y, w, h = int((bbox[0]/dim)*width), #\ #Saving the values of in array bbox into x,y,w,h. x in 0 index position of array and so on...
int((bbox[1]/dim)*height), \
int((bbox[2]/dim)*width), \
int((bbox[3]/dim)*height)
xmin, ymin, xmax, ymax = convertBack(float(x), float(y), float(w), float(h)) #calling function convertBack to get points for openCV
pt1 = (xmin, ymin)
pt2 = (xmax, ymax)
cv2.rectangle(img, pt1, pt2, colors[label], 1) #cv2.rectangle(image, start_point, end_point, color, thickness)
if label == 'with_mask':
string = label + str(i)
i+=1
else:
string = label
cv2.putText(img, string + ":" + str(round(confidence,2)),(pt1[0]-5, pt1[1] - 5), cv2.FONT_HERSHEY_SIMPLEX, 1,[0, 0, 255], 2)
return img
###############################################################################################################
#define and load the trained models into GPU's"
invt_configPath = "darknet/cfg/yolov3_custom_train.cfg"
invt_weightPath = "darknet/backup/yolov3_custom_train_last.weights"
invt_metaPath = "darknet/data/yolo.data"
network, class_names, colors = darknet.load_network(invt_configPath, invt_metaPath, invt_weightPath, batch_size=1)
invt_width = darknet.network_width(invt_network) #getting YOLO input image dimensions
invt_height = darknet.network_height(invt_network)
image = DrawBBoxes(invt_detections,frame,416,colors) #'name'_detections= detected class label, frame=detected image, 416=dimension of YOLO detection , colors of labels
#image = DrawBBoxes(ppe_detections,image,416)
cv2.imshow('Inventory Detections', image) #cv2.imshow("display window name", "video frame feed")
cv2.waitKey(10) #Displaying video for time in milliseconds per frame
cap.release()
#out.release()
cv2.destroyAllWindows()
###############################################################################################################
这darknet.py
是我从 AlexeyAB 的 GitHub 获得的。
该文件包含函数load_network
:
def load_network(config_file, data_file, weights, batch_size=1):
network = load_net_custom(
config_file.encode("ascii"),
weights.encode("ascii"), 0, batch_size)
metadata = load_meta(data_file.encode("ascii"))
class_names = [metadata.names[i].decode("ascii") for i in range(metadata.classes)]
colors = class_colors(class_names)
return network, class_names, colors
谁能告诉我如何解决这个错误?
解决方案
尝试在darknet文件夹中重命名darknet.py,然后:
import darknet2
推荐阅读
- php - PHPMAILER 中的 TLS 和 STARTTLS
- ionic-framework - 单击离子选择后如何使用值转到下一页
- angular - Twitter-bootstrap 模态在 Angular 中不起作用
- javascript - PHP 中的 CryptoJS AES 和 Nodejs 中的 CryptoJS.AES.decrypt
- amazon-web-services - DynamoDB - 分区分组或分片?
- python-3.x - 无点插值的最佳拟合
- tensorflow - TensorFlow 特定对象检测
- uiscrollview - 有没有办法在 SwiftUI 中制作分页的 ScrollView?
- html - 在 HTML5 中为 Input 标签初始化变量
- mule - 无法将“授权”标头发送到端点 - HTTP 模块 - Mulesoft 3.9