Spaces:
Sleeping
Sleeping
File size: 3,597 Bytes
b908f51 2d3238e 4bea016 b908f51 5b4ee5e 521ddf5 5b4ee5e b908f51 5b4ee5e f02352c 5f0be19 4bdbfb1 5b4ee5e 2d3238e 5b4ee5e 521ddf5 5f0be19 5b4ee5e 5f0be19 5b4ee5e 521ddf5 970c966 521ddf5 970c966 521ddf5 5b4ee5e 5f0be19 521ddf5 f02352c 8b59b01 5f0be19 8b59b01 5f0be19 8b59b01 5f0be19 8b59b01 5f0be19 970c966 8b59b01 b908f51 5529a00 b908f51 5529a00 b908f51 |
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "624c83c1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"DNN(\n",
" (fc_in): Linear(in_features=144, out_features=512, bias=True)\n",
" (residual_blocks): ModuleList(\n",
" (0-3): 4 x ResidualBlock(\n",
" (ln1): LayerNorm((512,), eps=1e-05, elementwise_affine=True)\n",
" (fc1): Linear(in_features=512, out_features=1024, bias=True)\n",
" (ln2): LayerNorm((1024,), eps=1e-05, elementwise_affine=True)\n",
" (fc2): Linear(in_features=1024, out_features=512, bias=True)\n",
" )\n",
" )\n",
" (fc_value): Sequential(\n",
" (0): Linear(in_features=512, out_features=64, bias=True)\n",
" (1): ReLU()\n",
" (2): Linear(in_features=64, out_features=1, bias=True)\n",
" )\n",
" (fc_policy): Sequential(\n",
" (0): Linear(in_features=512, out_features=64, bias=True)\n",
" (1): ReLU()\n",
" (2): Linear(in_features=64, out_features=12, bias=True)\n",
" )\n",
")"
]
},
"execution_count": 101,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from rlcube.models.models import DNN\n",
"from rlcube.envs.cube2 import Cube2Env\n",
"import torch\n",
"\n",
"net = DNN()\n",
"net.load(\"checkpoints/checkpoint_final.pth\")\n",
"net.eval()"
]
},
{
"cell_type": "code",
"execution_count": 103,
"id": "defde44e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[7, 11, 6, 7, 7, 10, 1, 0, 3, 3]\n",
"tensor([[ 0.9634],\n",
" [-0.0930],\n",
" [-0.8327],\n",
" [-0.0930],\n",
" [-0.8955],\n",
" [-1.8250],\n",
" [-4.0525],\n",
" [-1.8250],\n",
" [-3.0264],\n",
" [-3.6782]], grad_fn=<AddmmBackward0>)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
" 1%| | 8/1000 [00:00<00:10, 99.11it/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0, 2, 5, 2, 8, 6]\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
}
],
"source": [
"import numpy as np\n",
"from rlcube.models.search import MonteCarloTree\n",
"\n",
"env = Cube2Env()\n",
"\n",
"actions = []\n",
"obs = []\n",
"for _ in range(10):\n",
" action = env.action_space.sample()\n",
" actions.append(action.item())\n",
" env.step(action)\n",
" obs.append(env.obs())\n",
"\n",
"obs = torch.tensor(np.array(obs), dtype=torch.float32)\n",
"values, policies = net(obs)\n",
"print(actions)\n",
"print(values)\n",
"\n",
"\n",
"tree = MonteCarloTree(env.obs(), max_simulations=1000)\n",
"if tree.is_solved:\n",
" print([action for _, action in tree.solved_path])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|