Comments (1)
You can apply the method to any well-trained MLP policies after training. Usually, the weights of this MLP policy can be stored locally in TF or Torch format. We then convert them into numpy format like what play/torch_to_numpy.py
does, so we can reconstruct the policy with numpy. That is what ppo_inference_tf
does. In the numpy policy execution process, the neuron activations are recorded, enabling further analysis. Thus, if you want to use ppo_inference_tf
, you have to ensure your policy is a MLP policy trained with TF and convert it to numpy format. An example code is as follows given a policy trained with rllib
:
remove_value_network = True
path = "expert_weights.npz"
with open(ckpt_path, "rb") as f:
data = f.read()
unpickled = pickle.loads(data)
worker = pickle.loads(unpickled.pop("worker"))
if "_optimizer_variables" in worker["state"]["default_policy"]:
worker["state"]["default_policy"].pop("_optimizer_variables")
pickled_worker = pickle.dumps(worker)
weights = worker["state"]["default_policy"]
if remove_value_network:
weights = {k: v for k, v in weights.items() if "value" not in k}
np.savez_compressed(path, **weights)
print("Numpy agent weight is saved at: {}!".format(path))
Actually, you can record the neuron activation information in your torch or TF policy directly by logging information in the forward
function supposing it is a torch policy. In this way, the numpy conversion process can be removed. We additionally convert them into numpy format for aligning the inference process for both TF and Torch policies.
from policydissect.
Related Issues (7)
- Thank you for sharing your very interesting work HOT 1
- metadata-generation-failed by installation HOT 1
- setup.py tiny issue
- :display(warning): FrameBufferProperties available less than requested.
- Is there an example of how you ran the policy dissection for the gym environments? HOT 1
- Cannot run the MetaDrive Experiment HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from policydissect.