Created
January 14, 2023 06:35
Data transformation forHuggineFace model https://huggingface.co/peterkros/cvrp-model/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import pickle | |
import pandas as pd | |
#Read DataFrame from CSV | |
csv_file = pd.read_csv('./results/ADM_VRP_20_1024/data_pak_calc.csv') | |
df = csv_file[['latitude','longitude', 'demand']].head(10) | |
def create_data(graph_size, num_samples, is_save=True, filename=None, is_return=False, seed=1234): | |
"""Generate validation dataset (with SEED) and save | |
""" | |
CAPACITIES = { | |
10: 20., | |
20: 30., | |
50: 40., | |
100: 50. | |
} | |
depo = [33.7111702,73.4285812] | |
depo_respahed = tf.reshape(depo, (1,2)) | |
depo_tensor = tf.convert_to_tensor( depo_respahed, dtype=tf.float32) | |
tensor_A = tf.convert_to_tensor(df['latitude'].values, dtype=tf.float32) | |
tensor_B = tf.convert_to_tensor(df['longitude'].values, dtype=tf.float32) | |
# concatenate tensors along a new axis | |
concatenated_tensor = tf.concat([tensor_A, tensor_B], axis=-1) | |
# reshape the concatenated tensor | |
reshaped_tensor = tf.reshape(concatenated_tensor, (1,10,2)) | |
demand = tf.convert_to_tensor(df.demand.values, dtype=tf.float32) | |
demand_reshaped = tf.reshape(demand, (1,10)) | |
depo, graphs, demand = (depo_tensor, reshaped_tensor, demand_reshaped) | |
if is_save: | |
save_to_pickle('Validation_dataset_{}.pkl'.format(filename), (depo, graphs, demand)) | |
if is_return: | |
return tf.data.Dataset.from_tensor_slices((list(depo), list(graphs), list(demand))) | |
def save_to_pickle(filename, item): | |
"""Save to pickle | |
""" | |
with open(filename, 'wb') as handle: | |
pickle.dump(item, handle, protocol=pickle.HIGHEST_PROTOCOL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment