-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from appliedAI-Initiative/array_observation
Array observation
- Loading branch information
Showing
11 changed files
with
179 additions
and
37,003 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import os | ||
|
||
import SimpleITK as sitk | ||
from armscan_env.config import get_config | ||
from armscan_env.envs.labelmaps_navigation import LabelmapEnvTerminationCriterion | ||
from armscan_env.envs.observations import ( | ||
LabelmapClusterObservation, | ||
) | ||
from armscan_env.envs.rewards import LabelmapClusteringBasedReward | ||
from armscan_env.wrapper import ArmscanEnvFactory | ||
|
||
from tianshou.highlevel.config import SamplingConfig | ||
from tianshou.highlevel.env import VectorEnvType | ||
from tianshou.highlevel.experiment import ( | ||
ExperimentConfig, | ||
SACExperimentBuilder, | ||
) | ||
from tianshou.highlevel.params.alpha import AutoAlphaFactoryDefault | ||
from tianshou.highlevel.params.policy_params import SACParams | ||
from tianshou.utils.logging import datetime_tag | ||
|
||
config = get_config() | ||
|
||
volume_1 = sitk.ReadImage(config.get_labels_path(1)) | ||
volume_2 = sitk.ReadImage(config.get_labels_path(2)) | ||
|
||
log_name = os.path.join("sac", str(ExperimentConfig.seed), datetime_tag()) | ||
experiment_config = ExperimentConfig() | ||
|
||
sampling_config = SamplingConfig( | ||
num_epochs=10, | ||
step_per_epoch=100, | ||
num_train_envs=1, | ||
num_test_envs=1, | ||
buffer_size=1000, | ||
batch_size=256, | ||
step_per_collect=1, | ||
update_per_step=1, | ||
start_timesteps=0, | ||
start_timesteps_random=True, | ||
) | ||
|
||
volume_size = volume_1.GetSize() | ||
env_factory = ArmscanEnvFactory( | ||
name2volume={"1": volume_1}, | ||
observation=LabelmapClusterObservation(action_shape=(4,)), | ||
slice_shape=(volume_size[0], volume_size[2]), | ||
max_episode_len=20, | ||
rotation_bounds=(90.0, 45.0), | ||
translation_bounds=(0.0, None), | ||
render_mode="animation", | ||
seed=experiment_config.seed, | ||
venv_type=VectorEnvType.DUMMY, | ||
n_stack=4, | ||
termination_criterion=LabelmapEnvTerminationCriterion(min_reward_threshold=-0.1), | ||
reward_metric=LabelmapClusteringBasedReward(n_landmarks=(4, 2, 1)), | ||
) | ||
|
||
experiment = ( | ||
SACExperimentBuilder(env_factory, experiment_config, sampling_config) | ||
.with_sac_params( | ||
SACParams( | ||
tau=0.005, | ||
gamma=0.99, | ||
alpha=AutoAlphaFactoryDefault(lr=3e-4), | ||
estimation_step=1, | ||
actor_lr=1e-3, | ||
critic1_lr=1e-3, | ||
critic2_lr=1e-3, | ||
), | ||
) | ||
.with_actor_factory_default( | ||
(256, 256), | ||
continuous_unbounded=True, | ||
continuous_conditioned_sigma=True, | ||
) | ||
.with_common_critic_factory_default((256, 256)) | ||
.build() | ||
) | ||
|
||
experiment.run(run_name=log_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters