mmengine - WARNING - `Visualizer` backend is not initialized because save_dir is None.
时间: 2024-03-18 08:39:22 浏览: 122
这个警告信息来自于 mmengine 库,它表示 `Visualizer` 后端没有被初始化,因为 `save_dir` 参数的值为 None。`Visualizer` 是一个用于可视化训练过程和结果的工具,它可以用来绘制损失函数曲线、训练样本和模型输出等。在初始化 `Visualizer` 时,你需要指定一个保存输出结果的目录,如果 `save_dir` 参数为 None,那么 `Visualizer` 无法保存任何输出结果,因此就会出现上述警告信息。如果你想使用 `Visualizer`,请确保在初始化时指定一个有效的保存目录,例如:
```
from mmcv import Config
from mmdet.datasets import build_dataset
from mmdet.models import build_detector
from mmdet.apis import (train_detector, init_dist, get_root_logger,
set_random_seed, visualize)
cfg = Config.fromfile('configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py')
# 修改 save_dir 参数
cfg.work_dir = './work_dir'
# 其他代码不变
```
相关问题
def get_Image_dim_len(png_dir: str,jpg_dir:str): png = Image.open(png_dir) png_w,png_h=png.width,png.height #若第十行报错,说明jpg图片没有对应的png图片 png_dim_len = len(np.array(png).shape) assert png_dim_len==2,"提示:存在三维掩码图" jpg=Image.open(jpg_dir) jpg = ImageOps.exif_transpose(jpg) jpg.save(jpg_dir) jpg_w,jpg_h=jpg.width,jpg.height print(jpg_w,jpg_h,png_w,png_h) assert png_w==jpg_w and png_h==jpg_h,print("提示:%s mask图与原图宽高参数不一致"%(png_dir)) """2.读取单个图像均值和方差""" def pixel_operation(image_path: str): img = cv.imread(image_path, cv.IMREAD_COLOR) means, dev = cv.meanStdDev(img) return means,dev """3.分割数据集,生成label文件""" # 原始数据集 ann上一级 data_root = './work/voc_data02' #图像地址 image_dir="./JPEGImages" # ann图像文件夹 ann_dir = "./SegmentationClass" # txt文件保存路径 split_dir = './ImageSets/Segmentation' mmengine.mkdir_or_exist(osp.join(data_root, split_dir)) png_filename_list = [osp.splitext(filename)[0] for filename in mmengine.scandir( osp.join(data_root, ann_dir), suffix='.png')] jpg_filename_list=[osp.splitext(filename)[0] for filename in mmengine.scandir( osp.join(data_root, image_dir), suffix='.jpg')] assert len(jpg_filename_list)==len(png_filename_list),"提示:原图与掩码图数量不统一" print("数量检查无误") for i in range(10): random.shuffle(jpg_filename_list) red_num=0 black_num=0 with open(osp.join(data_root, split_dir, 'trainval.txt'), 'w+') as f: length = int(len(jpg_filename_list)) for line in jpg_filename_list[:length]: pngpath=osp.join(data_root,ann_dir,line+'.bmp') jpgpath=osp.join(data_root,image_dir,line+'.bmp') get_Image_dim_len(pngpath,jpgpath) img=cv.imread(pngpath,cv.IMREAD_GRAYSCALE) red_num+=len(img)*len(img[0])-len(img[img==0]) black_num+=len(img[img==0]) f.writelines(line + '\n') value=0 train_mean,train_dev=[[0.0,0.0,0.0]],[[0.0,0.0,0.0]] with open(osp.join(data_root, split_dir, 'train.txt'), 'w+') as f: train_length = int(len(jpg_filename_list) * 7/ 10) for line in jpg_filename_list[:train_length]: jpgpath=osp.join(data_root,image_dir,line+'.bmp') mean,dev=pixel_operation(jpgpath) train_mean+=mean train_dev+=dev f.writelines(line + '\n') with open(osp.join(data_root, split_dir, 'val.txt'), 'w+') as f: for line in jpg_filename_list[train_length:]: jpgpath=osp.join(data_root,image_dir,line+'.bmp') mean,dev=pixel_operation(jpgpath) train_mean+=mean train_dev+=dev f.writelines(line + '\n') 帮我把这段代码改成bmp图像可以制作数据集的代码
当然,我可以帮你将代码修改为支持bmp图像的数据集制作代码。请看下面的修改后的代码:
```python
from PIL import Image
import os
import random
import cv2 as cv
import numpy as np
def get_Image_dim_len(png_dir: str,jpg_dir:str):
png = Image.open(png_dir)
png_w,png_h=png.width,png.height
#若第十行报错,说明jpg图片没有对应的png图片
png_dim_len = len(np.array(png).shape)
assert png_dim_len==2,"提示:存在三维掩码图"
jpg=Image.open(jpg_dir)
jpg = jpg.transpose(Image.FLIP_LEFT_RIGHT) # 翻转图像
jpg.save(jpg_dir)
jpg_w,jpg_h=jpg.width,jpg.height
print(jpg_w,jpg_h,png_w,png_h)
assert png_w==jpg_w and png_h==jpg_h,print("提示:%s mask图与原图宽高参数不一致"%(png_dir))
def pixel_operation(image_path: str):
img = cv.imread(image_path, cv.IMREAD_COLOR)
means, dev = cv.meanStdDev(img)
return means,dev
data_root = './work/voc_data02'
image_dir="./JPEGImages"
ann_dir = "./SegmentationClass"
split_dir = './ImageSets/Segmentation'
os.makedirs(os.path.join(data_root, split_dir), exist_ok=True)
png_filename_list = [os.path.splitext(filename)[0] for filename in os.listdir(os.path.join(data_root, ann_dir)) if filename.endswith('.bmp')]
jpg_filename_list=[os.path.splitext(filename)[0] for filename in os.listdir(os.path.join(data_root, image_dir)) if filename.endswith('.bmp')]
assert len(jpg_filename_list)==len(png_filename_list),"提示:原图与掩码图数量不统一"
print("数量检查无误")
random.shuffle(jpg_filename_list)
red_num=0
black_num=0
with open(os.path.join(data_root, split_dir, 'trainval.txt'), 'w+') as f:
length = int(len(jpg_filename_list))
for line in jpg_filename_list[:length]:
pngpath=os.path.join(data_root,ann_dir,line+'.bmp')
jpgpath=os.path.join(data_root,image_dir,line+'.bmp')
get_Image_dim_len(pngpath,jpgpath)
img=cv.imread(pngpath,cv.IMREAD_GRAYSCALE)
red_num+=len(img)*len(img[0])-len(img[img==0])
black_num+=len(img[img==0])
f.writelines(line + '\n')
train_mean,train_dev=[[0.0,0.0,0.0]],[[0.0,0.0,0.0]]
with open(os.path.join(data_root, split_dir, 'train.txt'), 'w+') as f:
train_length = int(len(jpg_filename_list) * 7/ 10)
for line in jpg_filename_list[:train_length]:
jpgpath=os.path.join(data_root,image_dir,line+'.bmp')
mean,dev=pixel_operation(jpgpath)
train_mean+=mean
train_dev+=dev
f.writelines(line + '\n')
with open(os.path.join(data_root, split_dir, 'val.txt'), 'w+') as f:
for line in jpg_filename_list[train_length:]:
jpgpath=os.path.join(data_root,image_dir,line+'.bmp')
mean,dev=pixel_operation(jpgpath)
train_mean+=mean
train_dev+=dev
f.writelines(line + '\n')
```
希望这可以帮到你!如果你还有其他问题,请随时提问。
png_filename_list = [osp.splitext(filename)[0] for filename in mmengine.scandir( osp.join(data_root, ann_dir), suffix='.bmp')] jpg_filename_list=[osp.splitext(filename)[0] for filename in mmengine.scandir( osp.join(data_root, image_dir), suffix='.bmp')] assert len(jpg_filename_list)==len(png_filename_list),"提示:原图与掩码图数量不统一" print("数量检查无误") for i in range(10): random.shuffle(jpg_filename_list)
这段代码首先定义了两个列表:`png_filename_list`和`jpg_filename_list`,分别用于存储PNG图像文件和JPG图像文件的文件名(不包括扩展名)。
对于`png_filename_list`,使用了一个列表推导式,通过遍历指定目录下的所有以".bmp"为后缀的文件,将文件名的扩展名去除后存入列表中。
对于`jpg_filename_list`,同样使用了一个列表推导式,通过遍历指定目录下的所有以".bmp"为后缀的文件,将文件名的扩展名去除后存入列表中。
接下来,使用`assert`语句判断两个列表的长度是否相等,如果不相等,则会触发断言错误,并打印出提示信息。
然后,使用`print()`函数打印出"数量检查无误"的信息。
最后,使用循环语句对`jpg_filename_list`进行10次随机打乱操作,通过调用`random.shuffle()`函数实现随机排序。这样做可以在后续处理中随机选择图像文件,增加数据的随机性。
总结来说,这段代码的目的是获取指定目录下PNG图像文件和JPG图像文件的文件名,并对它们进行数量检查和随机排序。
阅读全文