Instructions to use devkumarhf/ur7e-sac-line-following with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- stable-baselines3
How to use devkumarhf/ur7e-sac-line-following with stable-baselines3:
from huggingface_sb3 import load_from_hub checkpoint = load_from_hub( repo_id="devkumarhf/ur7e-sac-line-following", filename="{MODEL FILENAME}.zip", ) - Notebooks
- Google Colab
- Kaggle
File size: 1,753 Bytes
1ce77ac | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | """Export the deterministic actor from the original trusted checkpoint."""
import os
os.environ['CUDA_VISIBLE_DEVICES']=''
from pathlib import Path
import json
import numpy as np
import torch
from checkpoint import load_model
from ur7e_traj_env import UR7eTrajEnv
from trajectory_generator import generate_trajectory
from policy import Policy
root=Path(__file__).resolve().parent;torch.set_num_threads(1);m=load_model();sd=m.actor.state_dict()
keys={'w1':'latent_pi.0.weight','b1':'latent_pi.0.bias','w2':'latent_pi.2.weight','b2':'latent_pi.2.bias','wmu':'mu.weight','bmu':'mu.bias'}
np.savez_compressed(root/'actor.npz',**{k:sd[v].cpu().numpy() for k,v in keys.items()});p=Policy()
errors=[];observations=[]
for seed in range(2026111700,2026111705):
traj,_=generate_trajectory(seed=seed);e=UR7eTrajEnv(fixed_trajectory=traj);o,_=e.reset()
for i in range(100):
a=m.predict(o,deterministic=True)[0];na=p.predict(o);errors.append(float(np.max(np.abs(a-na))));observations.append(o)
o,r,d,t,info=e.step(a)
if d or t:break
e.close()
batch=np.array(observations,dtype=np.float32);expected=np.array([m.predict(o,deterministic=True)[0] for o in batch]);batcherr=float(np.max(np.abs(p.predict(batch)-expected)))
assert max(errors)<1e-4 and batcherr<1e-4,(max(errors),batcherr)
result={'samples':len(errors),'single_max_abs_action_difference':max(errors),'batch_max_abs_action_difference':batcherr,'tolerance':1e-4,'reference':'Original Stable-Baselines3 deterministic SAC.predict on CPU','format':'NumPy NPZ; allow_pickle=False','export':'Deterministic mean actor only; original stochastic policy and optimizers retained in best_model.zip.'}
(root/'evaluation/actor-parity.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result))
|