-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadData.py
59 lines (54 loc) · 1.84 KB
/
LoadData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import torch
from torch import nn
from torch import nn, optim
from torch.utils.data import DataLoader
from torch.utils.data.dataloader import default_collate
from torch.nn import Sigmoid
import sys
import os
from collections import Counter
import string
import numpy as np
import argparse
class LoadData(torch.utils.data.Dataset):
def __init__(self,args):
self.args = args
self.data = self.get_data(args.data_path)
def get_data(self, data_path):
ret = []
with open(data_path, 'r') as f:
for line in f:
line = line.split('\n')[0]
category, cores, memory, disk, time = line.split(', ')
l = [int(category), int(cores), int(memory), int(disk), float(time)]
ret.append(l)
return ret
def __len__(self):
return len(self.data) - self.args.seqLength
def __getitem__(self, index):
#category_new, category, cores, memory, disk, time
#category, *cons = self.data[index]
X = []
y = []
for i in range(self.args.seqLength):
category, *cons = self.data[index+i]
if index+i == 0:
X.append([category] + self.data[index+i])
y.append(cons)
else:
X.append([category] + self.data[index+i-1])
y.append(cons)
return torch.Tensor(X), torch.Tensor(y)
# category, *cons = self.data[index]
# if index == 0:
# X = torch.Tensor([category] + self.data[index])
# X = X[None, :]
# y = torch.Tensor(cons)
# y = y[None, :]
# return X, y
# else:
# X = torch.Tensor([category] + self.data[index-1])
# X = X[None, :]
# y = torch.Tensor(cons)
# y = y[None, :]
# return X, y