- 一、Anaconda
- 安装后在开始菜单找不到的问题
-
打开cmd ,进入anaconda安装的位置,然后输入python .\Lib\_nsis.py mkmenus,注意“python” 与"."之间有空格。
- jupyter下看不到虚拟环境
-
在虚拟环境中安装这两个包
conda install ipykernel
conda install nb_conda
-
二、Labelimg
- 打开文件夹出现闪退
-
检查python版本是否为3.7,版本不能太高
- 三、图像文件的命名
-
采用全英文小写字母,不要含有一些特殊字符;
- 批量修改文件名,可以采用在pycharm运行:
-
import os for filename in os.listdir('C:/Users/Administrator/Desktop/data/train/ok/'): newname = filename.replace('ok.', 'ok') #把ok.换成ok os.rename('C:/Users/Administrator/Desktop/data/train/ok/'+filename, 'C:/Users/Administrator/Desktop/data/train/ok/'+newname)
- 四、标注文件
-
图像目标标注之后,确认产生的标注文件(以.xml为扩展名)和图像文件在同一个文件夹中;
-
标注名称一律使用全英文小写名称,不要含有特殊字符;标注的类别名称要提前确定好,因为模型训练时要使用到这些名称。
- 五、Git
- Gitbush
-
装好以后在要训练的文件夹里右键会有git bash here选项,不要在下载了git的文件夹打开
-
无法在gitbash里激活conda 虚拟环境
-
Git Bash窗口右键选项->文本,将字符集改为GBK,本地Locale改为zh_CN,重启Git Bash窗口,成功运行。
- 六、EAIDK-610环境部署
- 进入某一路径在terminal中是通过 cd 路径实现的
- 报错:Illegal instruction(cpre dumped)
- 如果报错:OpenBLAS Warning : Detect OpenMP Loop and this application may hang. Please rebuild the library with USE_OPENMP=1 option
- 七、获取全部文件名字并生成txt文件
-
import os import glob def extract_filenames_without_extension(directory, txt_file): file_list = glob.glob(os.path.join(directory, '*')) # 获取目录下所有文件的路径 filenames = [os.path.splitext(os.path.basename(file))[0] for file in file_list] # 去掉扩展名的文件名 with open(txt_file, 'w') as f: f.write('\n'.join(filenames)) # 将文件名写入txt文件,每个文件名占一行 # 示例用法 directory = 'C:/Users/Administrator/Desktop/kuo/training_data/lion_napkin/JPEGImages/' # 指定目录路径 txt_file = 'C:/Users/Administrator/Desktop/kuo/training_data/lion_napkin/JPEGImages/trainval.txt' # 指定生成名为trainval的txt文件路径 extract_filenames_without_extension(directory, txt_file)
- 八、数据扩增
-
# -*- coding: utf-8 -*- import cv2 import numpy as np import os.path import copy # 椒盐噪声 def SaltAndPepper(src, percetage): SP_NoiseImg = src.copy() SP_NoiseNum = int(percetage * src.shape[0] * src.shape[1]) for i in range(SP_NoiseNum): randR = np.random.randint(0, src.shape[0] - 1) randG = np.random.randint(0, src.shape[1] - 1) randB = np.random.randint(0, 3) if np.random.randint(0, 1) == 0: SP_NoiseImg[randR, randG, randB] = 0 else: SP_NoiseImg[randR, randG, randB] = 255 return SP_NoiseImg # 高斯噪声 def addGaussianNoise(image, percetage): G_Noiseimg = image.copy() w = image.shape[1] h = image.shape[0] G_NoiseNum = int(percetage * image.shape[0] * image.shape[1]) for i in range(G_NoiseNum): temp_x = np.random.randint(0, h) temp_y = np.random.randint(0, w) G_Noiseimg[temp_x][temp_y][np.random.randint(3)] = np.random.randn(1)[0] return G_Noiseimg # 昏暗 def darker(image, percetage=0.9): image_copy = image.copy() w = image.shape[1] h = image.shape[0] # get darker for xi in range(0, w): for xj in range(0, h): image_copy[xj, xi, 0] = int(image[xj, xi, 0] * percetage) image_copy[xj, xi, 1] = int(image[xj, xi, 1] * percetage) image_copy[xj, xi, 2] = int(image[xj, xi, 2] * percetage) return image_copy # 亮度 def brighter(image, percetage=1.5): image_copy = image.copy() w = image.shape[1] h = image.shape[0] # get brighter for xi in range(0, w): for xj in range(0, h): image_copy[xj, xi, 0] = np.clip(int(image[xj, xi, 0] * percetage), a_max=255, a_min=0) image_copy[xj, xi, 1] = np.clip(int(image[xj, xi, 1] * percetage), a_max=255, a_min=0) image_copy[xj, xi, 2] = np.clip(int(image[xj, xi, 2] * percetage), a_max=255, a_min=0) return image_copy # 旋转 def rotate(image, angle, center=None, scale=1.0): (h, w) = image.shape[:2] # If no rotation center is specified, the center of the image is set as the rotation center if center is None: center = (w / 2, h / 2) m = cv2.getRotationMatrix2D(center, angle, scale) rotated = cv2.warpAffine(image, m, (w, h)) return rotated # 翻转 def flip(image): flipped_image = np.fliplr(image) return flipped_image # 图片文件夹路径 file_dir = r'C:/Users/Administrator/Desktop/eaidk_obj_detect/training_data/lion_napkin/JPEGImages/' for img_name in os.listdir(file_dir): img_path = file_dir + img_name img = cv2.imread(img_path) # cv2.imshow("1",img) # cv2.waitKey(5000) # 旋转 rotated_90 = rotate(img, 90) cv2.imwrite(file_dir + img_name[0:-4] + '_r90.jpg', rotated_90) rotated_180 = rotate(img, 180) cv2.imwrite(file_dir + img_name[0:-4] + '_r180.jpg', rotated_180) for img_name in os.listdir(file_dir): img_path = file_dir + img_name img = cv2.imread(img_path) # 镜像 flipped_img = flip(img) cv2.imwrite(file_dir + img_name[0:-4] + '_fli.jpg', flipped_img) # 增加噪声 # img_salt = SaltAndPepper(img, 0.3) # cv2.imwrite(file_dir + img_name[0:7] + '_salt.jpg', img_salt) img_gauss = addGaussianNoise(img, 0.3) cv2.imwrite(file_dir + img_name[0:-4] + '_noise.jpg', img_gauss) # 变亮、变暗 img_darker = darker(img) cv2.imwrite(file_dir + img_name[0:-4] + '_darker.jpg', img_darker) img_brighter = brighter(img) cv2.imwrite(file_dir + img_name[0:-4] + '_brighter.jpg', img_brighter) blur = cv2.GaussianBlur(img, (7, 7), 1.5) # cv2.GaussianBlur(图像,卷积核,标准差) cv2.imwrite(file_dir + img_name[0:-4] + '_blur.jpg', blur)
图像处理一些注意事项
于 2023-09-12 19:55:34 首次发布