Ejemplo n.º 1
0
def process_data_links(line, r, s):
    # 输入链路序列line, 每个网络包含节点数量r,跳步数量s
    # 输出切分好的链路序列和节点数量
    arr = []
    for data in line:
        data1 = data.strip('\n')
        # a, b, _ = data1.split(',')  # 这里不同的数据即要做不同的处理
        a, b, c, d = data1.split(' ')
        arr.append([a, b])
    # list->array
    arr_2 = np.array(arr, int)
    node_num = np.max(arr_2)
    # print("共变化了多少时间点:", len(arr_2))

    data = []  # 最后的数据存放的矩阵

    i, j = 0, r  # i表示窗口头部坐标,j表示窗口尾部坐标
    while j < len(arr_2):
        links = arr_2[i:j, :]
        data.append(links)  # 加入最后存放数据的矩阵
        i, j = i + s, j + s  # 窗口滑动步长s

    # 处理最后不足窗口大小的时间点数量
    links = arr_2[len(arr_2) - r:len(arr_2), :]
    data.append(links)
    data = np.array(data)
    # print(data.shape)
    return data, node_num
Ejemplo n.º 2
0
    def __init__(self, data_root, train=True, transform=None):
        """
        Args:
            1. image folder
            2. data name, label list
            3. if train, loading data from train folder, or test folder
            4. 
        """
        self.root = data_root
        self.transform = transform
        self.train = train

        if train:
            data_list = os.path.join(self.root, 'train.csv')
        else:
            data_list = os.path.join(self.root, 'test.csv')

        with open(data_list) as fin:
            data_list = fin.readlines()

        self.img_paths = []
        self.img_labels = []

        self.n_data = 0
        for data in data_list[1:]:
            data = data.strip('\n').split(',')
            self.img_paths.append(data[0])
            self.img_labels.append(data[1])
            self.n_data += 1
Ejemplo n.º 3
0
def process_data_matrices(line, r, s):
    arr = []
    for data in line:
        data1 = data.strip('\n')
        # a, b, _ = data1.split(',')  # 这里不同的数据即要做不同的处理
        a, b, c, d = data1.split(' ')
        arr.append([a, b])
    # list->array
    arr_2 = np.array(arr, int)
    node_num = np.max(arr_2)
    # print("共变化了多少时间点:", len(arr_2))

    data = []  # 最后的数据存放的矩阵

    i, j = 0, r  # i表示窗口头部坐标,j表示窗口尾部坐标
    while j < len(arr_2):
        matric = np.eye(node_num).astype('int32')  # 这是每一份数据的矩阵,np.eye()表示增加了自环

        for k in range(i, j):
            # 每一个滑动窗口内连接的边都将矩阵相应位置变1
            matric[arr_2[k][0] - 1, arr_2[k][1] - 1] += 1
            matric[arr_2[k][1] - 1, arr_2[k][0] - 1] += 1
        data.append(matric)  # 加入最后存放数据的矩阵
        i, j = i + s, j + s  # 窗口滑动步长s

    # 处理最后不足窗口大小的时间点数量
    matric = np.eye(node_num).astype('int32')
    for k in range(i, len(arr_2)):
        matric[arr_2[k][0] - 1, arr_2[k][1] - 1] += 1
        matric[arr_2[k][1] - 1, arr_2[k][0] - 1] += 1
    data.append(matric)
    data = np.array(data)

    return data, node_num
Ejemplo n.º 4
0
    def __init__(self, dataset_name, train=True, transform=None, class_num=0):
        """
        Args:
            1. image folder
            2. data name, label list
            3. if train, loading data from train folder, or test folder
            4. 
        """
        self.dataset_name = dataset_name
        self.transform = transform
        self.train = train

        if train:
            data_list = os.path.join(constant.data_root, dataset_name,
                                     '{}_train.csv'.format(dataset_name))
        else:
            data_list = os.path.join(constant.data_root, dataset_name,
                                     '{}_test.csv'.format(dataset_name))

        with open(data_list) as fin:
            data_list = fin.readlines()

        self.img_paths = []
        self.img_labels = []

        self.n_data = 0
        self.class_cnt = dict()
        for data in data_list[1:]:
            data = data.strip('\n').split(',')
            img_path, label = data[0], data[1]
            self.img_paths.append(img_path)
            self.img_labels.append(label)
            self.n_data += 1

            if label in self.class_cnt.keys():
                self.class_cnt[label] += 1
            else:
                self.class_cnt[label] = 1

        self.classes = [
            name for name in os.listdir(
                os.path.join(constant.data_root, dataset_name))
            if 'csv' not in name
        ]
        self.classes = sorted(self.classes, key=lambda s: s.lower())

        if class_num > 0:
            pick_class_code = list(range(class_num))
            temp_img_path = []
            temp_img_label = []
            for (img_path, label) in zip(self.img_paths, self.img_labels):
                if int(label) in pick_class_code:
                    temp_img_path.append(img_path)
                    temp_img_label.append(label)

            self.img_paths = temp_img_path
            self.img_labels = temp_img_label
            self.classes = self.classes[:class_num]
Ejemplo n.º 5
0
    def __init__(self, image_root, landmark_file, transform):
        super(ImageFeatureFolder, self).__init__(root=image_root,
                                                 transform=transform)

        with open(landmark_file, 'r') as f:
            data = f.read()
        data = data.strip().split('\n')
        self.attrs = torch.FloatTensor(
            [list(map(float,
                      line.split()[1:])) for line in data[2:]])
Ejemplo n.º 6
0
    def preprocess(self, data):
        # pdb.set_trace()
        values = data.strip().split()
        labels = float(values[0])
        indexs = [
            int(v.split(':')[0]) - sum(self.feature_sizes[:i])
            for i, v in enumerate(values[1:])
        ]
        socres = [int(v.split(':')[1]) for v in values[1:]]

        # pdb.set_trace()
        return labels, torch.LongTensor(indexs), torch.FloatTensor(socres)
 def handle_data(self, data):
     if self.in_table:
         if data == 'Image Not Found':
             self.current_img = None
         elif self.current_tag == 'a':
             img_id = data.split('/')[-2]
             img_id = os.path.join(self.root, img_id + '_*.jpg')
             img_id = glob.glob(img_id)[0]
             self.current_img = img_id
             self.annotations[img_id] = []
         elif self.current_tag == 'li' and self.current_img:
             img_id = self.current_img
             self.annotations[img_id].append(data.strip())