Skip to content

Commit

Permalink
fixing import error
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamenot committed Jul 27, 2022
1 parent 350c41b commit 788a378
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
20 changes: 14 additions & 6 deletions smarts/env/wrappers/gif_recorder.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# MIT License
#
#
# Copyright (C) 2022. Huawei Technologies Co., Ltd. All rights reserved.
#
#
# 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 NON-INFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -20,9 +20,16 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import os
import sys
import subprocess

from moviepy.editor import ImageClip
from moviepy.editor import ImageSequenceClip
try:
from moviepy.editor import ImageClip
from moviepy.editor import ImageSequenceClip
except:
subprocess.check_call([sys.executable, "-m", "pip", "install", "moviepy"])
from moviepy.editor import ImageClip
from moviepy.editor import ImageSequenceClip
import shutil
import time
from pathlib import Path
Expand All @@ -32,6 +39,7 @@ class GifRecorder:
"""
Use images(rgb_array) to create a gif file.
"""

def __init__(self, dir, env):
timestamp_str = time.strftime("%Y%m%d-%H%M%S")
self.dir = dir + "_" + timestamp_str
Expand Down
15 changes: 7 additions & 8 deletions smarts/env/wrappers/recorder_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# MIT License
#
#
# Copyright (C) 2022. Huawei Technologies Co., Ltd. All rights reserved.
#
#
# 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 NON-INFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -20,8 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import os

from moviepy.editor import *
import gym
import gym.envs

Expand All @@ -32,6 +30,7 @@ class RecorderWrapper(gym.Wrapper):
"""
A Wrapper that interacts the gym environment with the GifRecorder to record video step by step.
"""

def __init__(self, dir, env):

try:
Expand Down Expand Up @@ -63,7 +62,7 @@ def start_recording(self):
if self.gif_recorder is None:
self.gif_recorder = GifRecorder(self.dir, self.env)
image = super().render(mode="rgb_array")
self.gif_recorder.capture_frame(self.next_frame_id(),image)
self.gif_recorder.capture_frame(self.next_frame_id(), image)
self.recording = True

def stop_recording(self):
Expand All @@ -79,7 +78,7 @@ def step(self, action):
observations, rewards, dones, infos = super().step(action)
if self.recording == True:
image = super().render(mode="rgb_array")
self.gif_recorder.capture_frame(self.next_frame_id(),image)
self.gif_recorder.capture_frame(self.next_frame_id(), image)

return observations, rewards, dones, infos

Expand Down

0 comments on commit 788a378

Please sign in to comment.