Skip to main content

Just use for myself

Project description

How to use

from ftd.module.detector import Detector

# 解析yaml配置文件
cfg = LoadYaml(opt.yaml)    
print(cfg) 
device=torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model=Detector(cfg.category_num,True).to(device)

# 数据预处理
ori_img = cv2.imread(opt.img)
res_img = cv2.resize(ori_img, (cfg.input_width, cfg.input_height), interpolation = cv2.INTER_LINEAR) 
img = res_img.reshape(1, cfg.input_height, cfg.input_width, 3)
img = torch.from_numpy(img.transpose(0, 3, 1, 2))
img = img.to(device).float() / 255.0

# 模型推理
start = time.perf_counter()
preds = model(img)
end = time.perf_counter()
time = (end - start) * 1000.
print("forward time:%fms"%time)

# 特征图后处理
output = handle_preds(preds, device, opt.thresh)

# 加载label names
LABEL_NAMES = []
with open(cfg.names, 'r') as f:
    for line in f.readlines():
        LABEL_NAMES.append(line.strip())

H, W, _ = ori_img.shape
scale_h, scale_w = H / cfg.input_height, W / cfg.input_width

# 绘制预测框
for box in output[0]:
    print(box)
    box = box.tolist()
    
    obj_score = box[4]
    category = LABEL_NAMES[int(box[5])]

    x1, y1 = int(box[0] * W), int(box[1] * H)
    x2, y2 = int(box[2] * W), int(box[3] * H)

    cv2.rectangle(ori_img, (x1, y1), (x2, y2), (255, 255, 0), 2)
    cv2.putText(ori_img, '%.2f' % obj_score, (x1, y1 - 5), 0, 0.7, (0, 255, 0), 2)	
    cv2.putText(ori_img, category, (x1, y1 - 25), 0, 0.7, (0, 255, 0), 2)

cv2.imwrite("result.png", ori_img)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ftdcherub-0.3.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ftdcherub-0.3-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file ftdcherub-0.3.tar.gz.

File metadata

  • Download URL: ftdcherub-0.3.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for ftdcherub-0.3.tar.gz
Algorithm Hash digest
SHA256 a2734f9902bd38f3cdfd0b1d6d039489bfa93a6c5d170934164bf0dfa1396613
MD5 5a38e22bbb469c95520405e60631a76b
BLAKE2b-256 e647e79d1be0dd25e3416aec5a56e65e9b71980c4d6a194e6e478c7e75768837

See more details on using hashes here.

File details

Details for the file ftdcherub-0.3-py3-none-any.whl.

File metadata

  • Download URL: ftdcherub-0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for ftdcherub-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ee7572675b17cea991efad942b72652793003a149c0588931ebe5102612c9305
MD5 1e9357079cfa98752fa09a6f4e9e2650
BLAKE2b-256 dea9ca938aca190cd0acc6975b0ef287239bc3abdd0754334fb29bbfdd3ca820

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page