(1)数据准备
数据集介绍:
数据集中存放的是1223幅图像,其中756个负样本(图像名称为0.1~0.756),458个正样本(图像名称为1.1~1.458),其中:"."前的标号为样本标签,"."后的标号为样本序号
(2)利用python读取文件夹中所有图像
1 ‘‘‘ 2 Load the image files form the folder 3 input: 4 imgDir: the direction of the folder 5 imgName:the name of the folder 6 output: 7 data:the data of the dataset 8 label:the label of the datset 9 ‘‘‘ 10 def load_Img(imgDir,imgFoldName): 11 imgs = os.listdir(imgDir+imgFoldName) 12 imgNum = len(imgs) 13 data = np.empty((imgNum,1,12,12),dtype="float32") 14 label = np.empty((imgNum,),dtype="uint8") 15 for i in range (imgNum): 16 img = Image.open(imgDir+imgFoldName+"/"+imgs[i]) 17 arr = np.asarray(img,dtype="float32") 18 data[i,:,:,:] = arr 19 label[i] = int(imgs[i].split(‘.‘)[0]) 20 return data,label
调用方式
1 craterDir = "./data/CraterImg/Adjust/" 2 foldName = "East_CraterAdjust12" 3 data, label = load_Img(craterDir,foldName)
时间: 2024-10-25 11:59:23