数据导入及验证

def load_data_from_gfootball(args):
data_path = "/home/longfei-fwxz/offline-rl/offline/datasets/gfootball/data/0890.pkl"
print("args:",args)
# envs = args["envs"]
envs = BCGFootball(args,rank=1)
# print("envs:",envs)
data = {}
data["obs"]=[]
data["next_obs"]=[]
data["action"]=[]
data["reward"]=[]
data["done"]=[]
data_path = "/home/longfei-fwxz/offline-rl/offline/datasets/gfootball/data/0890.pkl"
import pickle
fr=open(data_path,'rb')
inf = pickle.load(fr)

# n=pickle.load(f) #读出文件的数据个数
for i in range(len(inf)):
for k, v in inf[i].items():
for m in range(len(inf[i][k])):
if k == "obs":
obs = envs.raw2vec(inf[i][k][m])
data["obs"].append(obs)
 
if m == len(inf[i][k])-1:
done = 1
next_obs = obs #the last next_obs is equal to the obs
else:
done = 0
next_obs = envs.raw2vec(inf[i][k][m+1])
data["done"].append(done)
data["next_obs"].append(next_obs)
 
elif k == "action":
action = inf[i][k][m]
data["action"].append(action)
else:
reward = inf[i][k][m]
data["reward"].append(reward)
N=0
for i in range(len(inf[i][k])-1):
if (data["next_obs"][i] != data["obs"][i+1]).all():
print("exist error:",i)
else:
N += 1
print("no exist error:",N)

import pdb
pdb.set_trace()
posted @ 2021-09-18 17:47  呦呦南山  阅读(82)  评论(0编辑  收藏  举报