本文共 1345 字,大约阅读时间需要 4 分钟。
通过测试发现并未发现比多线程块更高效的方式来处理图片数据
以下是所需的主要库和模块:
import datetime import os import threading from concurrent.futures import ThreadPoolExecutor import numpy as np import logging import cv2 import torch from torch.utils.data import Dataset import xml.etree.ElementTree as ET from common import data_transforms CLASSES = ('mouse',) def aaa(listDataset): for index in range(len(listDataset.img_files)): if index in listDataset.img_d: pass else: img_path = listDataset.img_files[index % len(listDataset.img_files)].rstrip() img = cv2.imread(img_path, cv2.IMREAD_COLOR) if img is None: raise Exception("读取图片错误:{}".format(img_path)) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) h, w, c = img.shape label_path =
注意:上述优化后的代码主要进行了以下调整:
如果需要进一步优化或补充具体功能,请提供更多细节。
转载地址:http://tsfk.baihongyu.com/