building-agents/test.py

56 lines
1.2 KiB
Python
Raw Normal View History

2024-06-18 10:49:43 +08:00
# from joblib import load
#
# model = load('AgentPPO/reward_data.pkl')
#
# data = model['mean_episode_reward']
# print(data)
# import torch
#
# model_path = 'AgentDDPG/actor.pth'
#
# checkpoint = torch.load(model_path, map_location=torch.device('cuda'))
#
# # 如果.pth文件保存的是整个模型包含模型结构和参数
# model = checkpoint # 这里假设checkpoint直接就是模型实例有时候可能需要model.load_state_dict(checkpoint['state_dict'])
# 如果.pth文件仅保存了state_dict模型参数
# model = YourModelClass() # 实例化你的模型
# model.load_state_dict(checkpoint)
2024-06-24 11:54:21 +08:00
# print(model)
2024-06-18 10:49:43 +08:00
2024-06-24 14:18:06 +08:00
# import pickle
#
# a = 'DDPG'
# b = 'PPO'
# c = 'SAC'
# d = 'TD3'
#
# a1 = '/reward_data.pkl'
# a2 = '/loss_data.pkl'
# a3 = '/test_data.pkl'
#
# filename = './Agent' + a + a3
#
# # 使用 'rb' 模式打开文件,读取二进制数据
# with open(filename, 'rb') as f:
# data = pickle.load(f)
#
# print(data)
import json
2024-06-24 16:29:27 +08:00
import numpy as np
2024-06-18 10:49:43 +08:00
2024-06-24 16:29:27 +08:00
def get_llm_action(index) -> np.ndarray:
with open('data/llm_action.json', 'r') as file:
data = json.load(file)
normalized_index = index % len(data)
action = np.array(data[normalized_index])
return action
2024-06-18 10:49:43 +08:00
2024-06-24 16:29:27 +08:00
data = get_llm_action(2)
print(data)