@@ -226,6 +226,11 @@ def __init__(self, data_state, data_stress, itrain):
226
226
self .data_stress = data_stress
227
227
self .itrain = itrain
228
228
229
+ def _cvt_to_ndarray (self , list_dict ):
230
+ for key in list_dict :
231
+ list_dict [key ] = np .asarray (list_dict [key ])
232
+ return list_dict
233
+
229
234
def get (self , epochs = 1 ):
230
235
# Slow if using BatchSampler to obtain data
231
236
input_dict_train = {
@@ -243,7 +248,7 @@ def get(self, epochs=1):
243
248
label_dict_train = {"dummy_loss" : []}
244
249
label_dict_val = {"dummy_loss" : []}
245
250
for i in range (epochs ):
246
- shuffled_indices = paddle . randperm ( n = self .data_state .x_train .shape [0 ])
251
+ shuffled_indices = np . random . permutation ( self .data_state .x_train .shape [0 ])
247
252
input_dict_train ["state_x" ].append (
248
253
self .data_state .x_train [shuffled_indices [0 : self .itrain ]]
249
254
)
@@ -256,9 +261,9 @@ def get(self, epochs=1):
256
261
input_dict_train ["stress_y" ].append (
257
262
self .data_stress .y_train [shuffled_indices [0 : self .itrain ]]
258
263
)
259
- label_dict_train ["dummy_loss" ].append (paddle . to_tensor ( 0.0 ) )
264
+ label_dict_train ["dummy_loss" ].append (0.0 )
260
265
261
- shuffled_indices = paddle . randperm ( n = self .data_state .x_valid .shape [0 ])
266
+ shuffled_indices = np . random . permutation ( self .data_state .x_valid .shape [0 ])
262
267
input_dict_val ["state_x" ].append (
263
268
self .data_state .x_valid [shuffled_indices [0 : self .itrain ]]
264
269
)
@@ -271,7 +276,11 @@ def get(self, epochs=1):
271
276
input_dict_val ["stress_y" ].append (
272
277
self .data_stress .y_valid [shuffled_indices [0 : self .itrain ]]
273
278
)
274
- label_dict_val ["dummy_loss" ].append (paddle .to_tensor (0.0 ))
279
+ label_dict_val ["dummy_loss" ].append (0.0 )
280
+ input_dict_train = self ._cvt_to_ndarray (input_dict_train )
281
+ label_dict_train = self ._cvt_to_ndarray (label_dict_train )
282
+ input_dict_val = self ._cvt_to_ndarray (input_dict_val )
283
+ label_dict_val = self ._cvt_to_ndarray (label_dict_val )
275
284
return input_dict_train , label_dict_train , input_dict_val , label_dict_val
276
285
277
286
@@ -287,7 +296,7 @@ def __init__(self, dataset_path, train_p=0.6, cross_valid_p=0.2, test_p=0.2):
287
296
def get_shuffled_data (self ):
288
297
# Need to set the seed, otherwise the loss will not match the precision
289
298
ppsci .utils .misc .set_random_seed (seed = 10 )
290
- shuffled_indices = paddle . randperm ( n = self .x .shape [0 ])
299
+ shuffled_indices = np . random . permutation ( self .x .shape [0 ])
291
300
n_train = math .floor (self .train_p * self .x .shape [0 ])
292
301
n_cross_valid = math .floor (self .cross_valid_p * self .x .shape [0 ])
293
302
n_test = math .floor (self .test_p * self .x .shape [0 ])
0 commit comments