Commit 957a8477 authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

add rand tensor and typo

parent 7159f38b
......@@ -28,8 +28,6 @@ class class_ts_img():
self.horizon_length=params['target']['horizon_length']
self.SCALED = False
self.scaler=scaling_dict[params['scaling']]
tmp = pd.read_csv(path)#.sort_values(by=date)
tmp = pd.read_csv(path)#.sort_values(by=date)
## subset indice
if subset_indice is not None:
......@@ -48,10 +46,11 @@ class class_ts_img():
self.features = features + [s + '_sin' for s in features_cyclic] + [s + '_cos' for s in features_cyclic]
else:
self.features = features
if images is not None:
self.df_images = tmp.loc[self.indice, self.images]
self.df_features = tmp.loc[self.indice, self.features]
self.scale_param_features = param_scale(self.df_features,params['scaling'])
# images
if images is not None:
self.df_images = tmp.loc[self.indice, self.images]
## target
if self.target is not None:
self.df_target = tmp.loc[self.indice, self.target]
......@@ -76,12 +75,16 @@ class class_ts_img():
tmp = self.df_features.iloc[indice_i]
features_data = torch.from_numpy(tmp.to_numpy()).float()
#images
tmp = self.df_images.iloc[indice_i]
np_images = []
for index, row in tmp.iterrows():
if (self.history_length>0):
for index in indice_i:
for k in self.images:
filename = self.df_images.loc[self.indice[index],k]
# TODO: like https://pytorch.org/vision/0.9/_modules/torchvision/datasets/cifar.html
np_images.append(img_as_float(io.imread(os.path.join(self.imgdir,filename))))
else:
for k in self.images:
filename = row[k]
# TODO: like https://pytorch.org/vision/0.9/_modules/torchvision/datasets/cifar.html
filename = self.df_images.loc[self.indice[indice_i],k]
np_images.append(img_as_float(io.imread(os.path.join(self.imgdir,filename))))
image_data = torch.from_numpy(np.array(np_images))
image_data = image_data.permute((0, 3, 1, 2)).float() # channels, row, columns
......@@ -93,9 +96,9 @@ class class_ts_img():
indice_target_i = id
tmp = self.df_target.iloc[indice_target_i]
target_data = torch.from_numpy(tmp.to_numpy()).float()
return features_data, image_data, target_data
return features_data, image_data[0], target_data
else:
return features_data, image_data
return features_data, image_data[0]
def __len__(self) -> int:
return len(self.df_features.index)
......@@ -104,6 +107,35 @@ class class_ts_img():
def nb_input(self) -> int:
return(2)
def get_rand_input(self):
id = 1
#features
if (self.history_length>0):
indice_i = range(id,(self.history_length + id))
else:
indice_i = id
tmp = self.df_features.iloc[indice_i]
features_data = torch.from_numpy(tmp.to_numpy()).float()
size = tuple([1]) + tuple(features_data.shape) # batch (random), size of features_data
x_f = torch.randn(size)
#images
np_images = []
if (self.history_length>0):
for index in indice_i:
for k in self.images:
filename = self.df_images.loc[self.indice[index],k]
# TODO: like https://pytorch.org/vision/0.9/_modules/torchvision/datasets/cifar.html
np_images.append(img_as_float(io.imread(os.path.join(self.imgdir,filename))))
else:
for k in self.images:
filename = self.df_images.loc[self.indice[indice_i],k]
np_images.append(img_as_float(io.imread(os.path.join(self.imgdir,filename))))
image_data = torch.from_numpy(np.array(np_images))
image_data = image_data.permute((0, 3, 1, 2)).float() # x, channels, row, columns
size = tuple([1]) + tuple(image_data[0].shape) # batch (random), size of image_data
x_img = torch.randn(size)
return (x_f, x_img)
def scale(self):
if self.SCALED == False:
self.df_features=self.scaler(self.df_features, self.scale_param_features, True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment