import numpy as npimport osimport scipyio as sciofrom torchutilsdata import Datasetdef normalizedata # 归一化到0-255 rawdata_max = maxmapmax data rawdata_min = minmapmin data for i in rangedatas
This code defines a custom dataset class called MyDataset.
The class takes in three parameters: root_dir (the root directory where the data is stored), names_file (a file containing the names of the data files and their corresponding labels), and transform (an optional data transformation function).
The normalize function is a helper function that normalizes the input data to the range of 0-255.
The MyDataset class inherits from the torch.utils.data.Dataset class and overrides the len and getitem methods.
len returns the size of the dataset, which is the number of samples in the names_file.
getitem takes an index as input and loads the corresponding data file using the root_dir and names_list. It then normalizes the data using the normalize function and returns a dictionary containing the data and its label.
If a transform function is provided, it is applied to the sample before returning it.
Overall, this code sets up a custom dataset class for loading and preprocessing data for machine learning tasks.
原文地址: http://www.cveoy.top/t/topic/ib4S 著作权归作者所有。请勿转载和采集!