diff --git a/README.md b/README.md index 66dc04e..312222f 100644 --- a/README.md +++ b/README.md @@ -57,12 +57,12 @@ Prediction is sampled after 110K iterations, and I only implemented one-step tra * MacOS 10.12 or Ubuntu 16.04 * PyTorch v0.4.0 * Python 3.6, 3.5 or 2.7 (deprecated) -* Core dependencies: `pip install -r requirements.txt` +* Core dependencies: `pip install -e .` * Optional: [Roboschool](https://github.com/openai/roboschool), [DeepMind Control Suite](https://github.com/deepmind/dm_control)+[DMControl2Gym](dm_control2gym) # Usage -```main.py``` contains examples for all the implemented algorithms +```examples.py``` contains examples for all the implemented algorithms # References * [Human Level Control through Deep Reinforcement Learning](https://www.nature.com/nature/journal/v518/n7540/full/nature14236.html) diff --git a/deep_rl/__init__.py b/deep_rl/__init__.py new file mode 100644 index 0000000..ee3be34 --- /dev/null +++ b/deep_rl/__init__.py @@ -0,0 +1,5 @@ +from .agent import * +from .component import * +from .model import * +from .network import * +from .utils import * \ No newline at end of file diff --git a/agent/A2C_agent.py b/deep_rl/agent/A2C_agent.py similarity index 96% rename from agent/A2C_agent.py rename to deep_rl/agent/A2C_agent.py index 0c71e40..327ee9d 100644 --- a/agent/A2C_agent.py +++ b/deep_rl/agent/A2C_agent.py @@ -4,14 +4,9 @@ # declaration at the top # ####################################################################### -import numpy as np -from network import * -from utils import * -from component import * +from ..network import * +from ..component import * from .BaseAgent import * -import pickle -import os -import time class A2CAgent(BaseAgent): def __init__(self, config): diff --git a/agent/BaseAgent.py b/deep_rl/agent/BaseAgent.py similarity index 100% rename from agent/BaseAgent.py rename to deep_rl/agent/BaseAgent.py diff --git a/agent/CategoricalDQN_agent.py b/deep_rl/agent/CategoricalDQN_agent.py similarity index 97% rename from agent/CategoricalDQN_agent.py rename to deep_rl/agent/CategoricalDQN_agent.py index bae59d1..d9e92c9 100644 --- a/agent/CategoricalDQN_agent.py +++ b/deep_rl/agent/CategoricalDQN_agent.py @@ -4,14 +4,10 @@ # declaration at the top # ####################################################################### -from network import * -from component import * -from utils import * -import numpy as np +from ..network import * +from ..component import * +from ..utils import * import time -import os -import pickle -import torch from .BaseAgent import * class CategoricalDQNAgent(BaseAgent): diff --git a/agent/DDPG_agent.py b/deep_rl/agent/DDPG_agent.py similarity index 96% rename from agent/DDPG_agent.py rename to deep_rl/agent/DDPG_agent.py index a36243c..6b48e08 100644 --- a/agent/DDPG_agent.py +++ b/deep_rl/agent/DDPG_agent.py @@ -4,14 +4,8 @@ # declaration at the top # ####################################################################### -import numpy as np -import torch.multiprocessing as mp -from network import * -from utils import * -from component import * -import pickle -import os -import time +from ..network import * +from ..component import * from .BaseAgent import * class DDPGAgent(BaseAgent): diff --git a/agent/DQN_agent.py b/deep_rl/agent/DQN_agent.py similarity index 97% rename from agent/DQN_agent.py rename to deep_rl/agent/DQN_agent.py index ccb2974..2d2f433 100644 --- a/agent/DQN_agent.py +++ b/deep_rl/agent/DQN_agent.py @@ -4,14 +4,10 @@ # declaration at the top # ####################################################################### -from network import * -from component import * -from utils import * -import numpy as np +from ..network import * +from ..component import * +from ..utils import * import time -import os -import pickle -import torch from .BaseAgent import * class DQNAgent(BaseAgent): diff --git a/agent/NStepDQN_agent.py b/deep_rl/agent/NStepDQN_agent.py similarity index 95% rename from agent/NStepDQN_agent.py rename to deep_rl/agent/NStepDQN_agent.py index 61fa1b8..bf27e63 100644 --- a/agent/NStepDQN_agent.py +++ b/deep_rl/agent/NStepDQN_agent.py @@ -4,14 +4,9 @@ # declaration at the top # ####################################################################### -from network import * -from component import * -from utils import * -import numpy as np -import time -import os -import pickle -import torch +from ..network import * +from ..component import * +from ..utils import * from .BaseAgent import * class NStepDQNAgent(BaseAgent): diff --git a/agent/PPO_agent.py b/deep_rl/agent/PPO_agent.py similarity index 96% rename from agent/PPO_agent.py rename to deep_rl/agent/PPO_agent.py index 89d4b14..eb3c11b 100644 --- a/agent/PPO_agent.py +++ b/deep_rl/agent/PPO_agent.py @@ -4,14 +4,8 @@ # declaration at the top # ####################################################################### -import numpy as np -import torch.multiprocessing as mp -from network import * -from utils import * -from component import * -import pickle -import os -import time +from ..network import * +from ..component import * from .BaseAgent import * class PPOAgent(BaseAgent): diff --git a/agent/QuantileRegressionDQN_agent.py b/deep_rl/agent/QuantileRegressionDQN_agent.py similarity index 97% rename from agent/QuantileRegressionDQN_agent.py rename to deep_rl/agent/QuantileRegressionDQN_agent.py index e5b83b2..a23faf2 100644 --- a/agent/QuantileRegressionDQN_agent.py +++ b/deep_rl/agent/QuantileRegressionDQN_agent.py @@ -4,14 +4,10 @@ # declaration at the top # ####################################################################### -from network import * -from component import * -from utils import * -import numpy as np +from ..network import * +from ..component import * +from ..utils import * import time -import os -import pickle -import torch from .BaseAgent import * class QuantileRegressionDQNAgent(BaseAgent): diff --git a/agent/__init__.py b/deep_rl/agent/__init__.py similarity index 100% rename from agent/__init__.py rename to deep_rl/agent/__init__.py diff --git a/component/__init__.py b/deep_rl/component/__init__.py similarity index 100% rename from component/__init__.py rename to deep_rl/component/__init__.py diff --git a/component/atari_wrapper.py b/deep_rl/component/atari_wrapper.py similarity index 99% rename from component/atari_wrapper.py rename to deep_rl/component/atari_wrapper.py index 2b575fc..a4df712 100644 --- a/component/atari_wrapper.py +++ b/deep_rl/component/atari_wrapper.py @@ -1,7 +1,6 @@ # based on https://github.com/openai/baselines/blob/master/baselines/common/atari_wrappers.py import numpy as np -from collections import deque import gym from gym import spaces from gym.spaces import Box diff --git a/component/bench.py b/deep_rl/component/bench.py similarity index 100% rename from component/bench.py rename to deep_rl/component/bench.py diff --git a/component/policy.py b/deep_rl/component/policy.py similarity index 100% rename from component/policy.py rename to deep_rl/component/policy.py diff --git a/component/random_process.py b/deep_rl/component/random_process.py similarity index 100% rename from component/random_process.py rename to deep_rl/component/random_process.py diff --git a/component/replay.py b/deep_rl/component/replay.py similarity index 98% rename from component/replay.py rename to deep_rl/component/replay.py index fda18a1..a9bef35 100644 --- a/component/replay.py +++ b/deep_rl/component/replay.py @@ -5,9 +5,6 @@ ####################################################################### import numpy as np -import torch -import random -import torch.multiprocessing as mp class Replay: def __init__(self, memory_size, batch_size): diff --git a/component/task.py b/deep_rl/component/task.py similarity index 98% rename from component/task.py rename to deep_rl/component/task.py index d2a1a36..933bbc6 100644 --- a/component/task.py +++ b/deep_rl/component/task.py @@ -3,15 +3,11 @@ # Permission given to modify the code as long as you keep this # # declaration at the top # ####################################################################### -import gym -import sys -import numpy as np from .atari_wrapper import * import multiprocessing as mp import sys from .bench import Monitor -from utils import * -import datetime +from ..utils import * import uuid class BaseTask: diff --git a/model/__init__.py b/deep_rl/model/__init__.py similarity index 100% rename from model/__init__.py rename to deep_rl/model/__init__.py diff --git a/model/action_conditional_video_prediction.py b/deep_rl/model/action_conditional_video_prediction.py similarity index 97% rename from model/action_conditional_video_prediction.py rename to deep_rl/model/action_conditional_video_prediction.py index a28b7b0..2c7e45a 100644 --- a/model/action_conditional_video_prediction.py +++ b/deep_rl/model/action_conditional_video_prediction.py @@ -6,20 +6,14 @@ __all__ = ['acvp_train'] -import torch -from torch.autograd import Variable -import torch.nn as nn -import torch.nn.functional as F -import numpy as np -import pickle import torchvision from skimage import io from collections import deque import gym import torch.optim -from utils import * +from deep_rl.utils import * from tqdm import tqdm -from network import * +from deep_rl.network import * class Network(nn.Module, BaseNet): def __init__(self, num_actions, gpu=0): diff --git a/model/dataset.py b/deep_rl/model/dataset.py similarity index 97% rename from model/dataset.py rename to deep_rl/model/dataset.py index 7f601e4..a97ccea 100644 --- a/model/dataset.py +++ b/deep_rl/model/dataset.py @@ -6,10 +6,9 @@ __all__ = ['generate_dataset'] -import logging -from agent import * -from component import * -from utils import * +from ..agent import * +from ..component import * +from deep_rl.utils import * from skimage import io def episode(agent, task): diff --git a/network/__init__.py b/deep_rl/network/__init__.py similarity index 100% rename from network/__init__.py rename to deep_rl/network/__init__.py diff --git a/network/network_bodies.py b/deep_rl/network/network_bodies.py similarity index 100% rename from network/network_bodies.py rename to deep_rl/network/network_bodies.py diff --git a/network/network_heads.py b/deep_rl/network/network_heads.py similarity index 100% rename from network/network_heads.py rename to deep_rl/network/network_heads.py diff --git a/network/network_utils.py b/deep_rl/network/network_utils.py similarity index 99% rename from network/network_utils.py rename to deep_rl/network/network_utils.py index 3a54b7b..79d6fb2 100644 --- a/network/network_utils.py +++ b/deep_rl/network/network_utils.py @@ -7,7 +7,6 @@ import torch import torch.nn as nn import torch.nn.functional as F -import numpy as np class BaseNet: def set_gpu(self, gpu): diff --git a/utils/__init__.py b/deep_rl/utils/__init__.py similarity index 100% rename from utils/__init__.py rename to deep_rl/utils/__init__.py diff --git a/utils/config.py b/deep_rl/utils/config.py similarity index 100% rename from utils/config.py rename to deep_rl/utils/config.py diff --git a/utils/misc.py b/deep_rl/utils/misc.py similarity index 99% rename from utils/misc.py rename to deep_rl/utils/misc.py index b07af58..a4aa07c 100644 --- a/utils/misc.py +++ b/deep_rl/utils/misc.py @@ -8,7 +8,6 @@ import numpy as np import pickle import os import datetime -import uuid import torch try: # python >= 3.5 diff --git a/utils/normalizer.py b/deep_rl/utils/normalizer.py similarity index 99% rename from utils/normalizer.py rename to deep_rl/utils/normalizer.py index dbaaee1..95ffd47 100644 --- a/utils/normalizer.py +++ b/deep_rl/utils/normalizer.py @@ -3,7 +3,6 @@ # Permission given to modify the code as long as you keep this # # declaration at the top # ####################################################################### -import torch import numpy as np class BaseNormalizer: diff --git a/utils/plot.py b/deep_rl/utils/plot.py similarity index 99% rename from utils/plot.py rename to deep_rl/utils/plot.py index 10f66fa..0869174 100644 --- a/utils/plot.py +++ b/deep_rl/utils/plot.py @@ -1,7 +1,7 @@ # Adapted from https://github.com/openai/baselines/blob/master/baselines/results_plotter.py import numpy as np -import component +from ..component import * import os import re diff --git a/utils/schedule.py b/deep_rl/utils/schedule.py similarity index 100% rename from utils/schedule.py rename to deep_rl/utils/schedule.py diff --git a/utils/tf_logger.py b/deep_rl/utils/tf_logger.py similarity index 100% rename from utils/tf_logger.py rename to deep_rl/utils/tf_logger.py diff --git a/main.py b/examples.py similarity index 99% rename from main.py rename to examples.py index 1211b82..9870b6a 100644 --- a/main.py +++ b/examples.py @@ -4,11 +4,7 @@ # declaration at the top # ####################################################################### -import logging -from agent import * -from component import * -from utils import * -from model import * +from deep_rl import * ## cart pole diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 7a37e6d..0000000 --- a/requirements.txt +++ /dev/null @@ -1,12 +0,0 @@ -torch>=0.4.0 -torchvision>=0.2.1 -gym>=0.10.5 -atari-py>=0.1.1 -opencv-python>=3.4.0.12 -tensorboardX==1.1 -scikit-image>=0.13.1 -tqdm>=4.23.0 -pandas>=0.22.0 -pathlib2>=1.0.1;python_version <= '2.7' -pathlib>=1.0.1;python_version >= '3.5' -seaborn>=0.8.1 \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..ae1d011 --- /dev/null +++ b/setup.py @@ -0,0 +1,31 @@ +from setuptools import setup, find_packages +import sys + +if sys.version.startswith('2.7'): + pathlib = 'pathlib2>=1.0.1' +elif sys.version.startswith('3.5') or sys.version.startswith('3.6'): + pathlib = 'pathlib>=1.0.1' +else: + raise Exception('Only Python 2.7, 3.5 and 3.6 are supported') + +setup(name='deep_rl', + packages=[package for package in find_packages() + if package.startswith('deep_rl')], + install_requires=[ + 'torch>=0.4.0', + 'torchvision>=0.2.1', + 'gym>=0.10.5', + 'atari-py>=0.1.1', + 'opencv-python>=3.4.0.12', + 'tensorboardX==1.1', + 'scikit-image>=0.13.1', + 'tqdm>=4.23.0', + 'pandas>=0.22.0', + 'seaborn>=0.8.1', + pathlib + ], + description="Highly modularized implementation of popular deep RL algorithms", + author="Shangtong Zhang", + url='https://github.com/ShangtongZhang/DeepRL', + author_email="zhangshangtong.cpp@gmail.com", + version="0.2")