-
Notifications
You must be signed in to change notification settings - Fork 599
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 #837 from microsoft/malmoenvvideo
add video recording
- Loading branch information
Showing
3 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
|
||
setuptools.setup( | ||
name="malmoenv", | ||
version="0.0.6", | ||
version="0.0.7", | ||
author="Andre Kramer", | ||
author_email="[email protected]", | ||
description="A gym environemnt for Malmo", | ||
|
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,84 @@ | ||
# ------------------------------------------------------------------------------------------------ | ||
# Copyright (c) 2018 Microsoft Corporation | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
# associated documentation files (the "Software"), to deal in the Software without restriction, | ||
# including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all copies or | ||
# substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT | ||
# NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
# ------------------------------------------------------------------------------------------------ | ||
|
||
import malmoenv | ||
import argparse | ||
from pathlib import Path | ||
import time | ||
import gym | ||
from gym.wrappers.monitoring.video_recorder import VideoRecorder | ||
|
||
import logging | ||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
if __name__ == '__main__': | ||
|
||
parser = argparse.ArgumentParser(description='malmovnv test') | ||
parser.add_argument('--mission', type=str, default='missions/mobchase_single_agent.xml', help='the mission xml') | ||
parser.add_argument('--port', type=int, default=9000, help='the mission server port') | ||
parser.add_argument('--server', type=str, default='127.0.0.1', help='the mission server DNS or IP address') | ||
parser.add_argument('--port2', type=int, default=None, help="(Multi-agent) role N's mission port. Defaults to server port.") | ||
parser.add_argument('--server2', type=str, default=None, help="(Multi-agent) role N's server DNS or IP") | ||
parser.add_argument('--episodes', type=int, default=1, help='the number of resets to perform - default is 1') | ||
parser.add_argument('--episode', type=int, default=0, help='the start episode - default is 0') | ||
parser.add_argument('--role', type=int, default=0, help='the agent role - defaults to 0') | ||
parser.add_argument('--episodemaxsteps', type=int, default=0, help='max number of steps per episode') | ||
parser.add_argument('--resync', type=int, default=0, help='exit and re-sync every N resets' | ||
' - default is 0 meaning never.') | ||
parser.add_argument('--experimentUniqueId', type=str, default='test1', help="the experiment's unique id.") | ||
parser.add_argument('--video_path', type=str, default="video.mp4", help="Optional video path.") | ||
args = parser.parse_args() | ||
if args.server2 is None: | ||
args.server2 = args.server | ||
|
||
xml = Path(args.mission).read_text() | ||
env = malmoenv.make() | ||
|
||
env.init(xml, args.port, | ||
server=args.server, | ||
server2=args.server2, port2=args.port2, | ||
role=args.role, | ||
exp_uid=args.experimentUniqueId, | ||
episode=args.episode, | ||
resync=args.resync, | ||
reshape=True) | ||
|
||
rec = VideoRecorder(env, args.video_path) | ||
|
||
for i in range(args.episodes): | ||
print("reset " + str(i)) | ||
obs = env.reset() | ||
rec.capture_frame() | ||
|
||
steps = 0 | ||
done = False | ||
while not done and (args.episodemaxsteps <= 0 or steps < args.episodemaxsteps): | ||
action = env.action_space.sample() | ||
rec.capture_frame() | ||
obs, reward, done, info = env.step(action) | ||
steps += 1 | ||
print("reward: " + str(reward)) | ||
# print("done: " + str(done)) | ||
print("obs: " + str(obs)) | ||
# print("info" + info) | ||
|
||
time.sleep(.05) | ||
|
||
rec.close() | ||
env.close() |