question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'NoneType' object has no attribute 'get'

See original GitHub issue

**Hello, I got a issue when learning a custom environment. Please give me some advices, thank you!

from stable_baselines import A2C
from stable_baselines.common.cmd_util import make_vec_env
import numpy as np
# instantiate the env
np.random.seed(0)
env = gym.make('MyHEM-v0')
env = make_vec_env(lambda: env, n_envs = 1)
model = A2C('MlpPolicy', env, gamma=1.0, verbose=1)
model.learn(total_timesteps=5000)

**My error is**
---------------------------------------------------------------------------
 AttributeError: 'NoneType' object has no attribute 'get'


**My environment code is roughly like this**
---------------------------------------------------------------------------
import random
import json
import gym
from gym import spaces
import pandas as pd
import numpy as np

class HEMS01(gym.Env):
    metadata = {'render.modes': ['human']}

    def __init__(self,):
        super(HEMS01, self).__init__()
        self.appliances_number = 1
        self.electricity_cost = np.array([5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 12, 12, 5, 5, 5, 5, 10, 10, 10, 5, 5, 5])
        self.appliances_consumption = 1
        self.schedule_start =10
        self.schedule_stop = 20
        self.time_stamp = 0
        ##  Action of the format
        n_actions = 2
        self.action_space = spaces.Discrete(n_actions)
        # discribe by Discrete and Box space
        self.observation_space = spaces.Box(low = 0, high = 24,
                                            shape=(1,5), dtype = np.float32)
        self.done = False
        self.time_stamp = 0
        self.state_accumulation = 0
        self.episode_rewards = []
        self.history_actions = []
        
    def get_action_shape(self):
        return 1
    
    def reset(self):
        self.done = False
        self.time_stamp = 0
        self.state_accumulation = 0
        self.history_actions = []
        return self.get_obs()
    
    def get_obs_shape(self):
        return np.shape(self.get_obs())
    
    def get_obs(self):
        return [self.time_stamp,self.state_accumulation,self.schedule_start,
               self.usage_duration,self.schedule_stop]

    def reward(self, action):
          pass

    def seed(self, seed=None):
        self.np_random, seed = seeding.np_random(seed)
        return [seed]

    def step(self, action):
        pass

    def render(self, mode='human', close=False):
        pass

    def close(self):
        pass


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-16-b7dcb49ceb4c> in <module>
      8 env = make_vec_env(lambda: env, n_envs = 1)
      9 model = A2C('MlpPolicy', env, gamma=1.0, verbose=1)
---> 10 model.learn(total_timesteps=5000)
     11 #model.learn(total_timesteps=5000)

~\Anaconda3\envs\pytorch\lib\site-packages\stable_baselines\a2c\a2c.py in learn(self, total_timesteps, callback, log_interval, tb_log_name, reset_num_timesteps)
    259                 callback.on_rollout_start()
    260                 # true_reward is the reward without discount
--> 261                 rollout = self.runner.run(callback)
    262                 # unpack
    263                 obs, states, rewards, masks, actions, values, ep_infos, true_reward = rollout

~\Anaconda3\envs\pytorch\lib\site-packages\stable_baselines\common\runners.py in run(self, callback)
     46         self.callback = callback
     47         self.continue_training = True
---> 48         return self._run()
     49 
     50     @abstractmethod

~\Anaconda3\envs\pytorch\lib\site-packages\stable_baselines\a2c\a2c.py in _run(self)
    370 
    371             for info in infos:
--> 372                 maybe_ep_info = info.get('episode')
    373                 if maybe_ep_info is not None:
    374                     ep_infos.append(maybe_ep_info)

AttributeError: 'NoneType' object has no attribute 'get'

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
chyunf001commented, Jul 6, 2020

The issue has been solved perfectly with your guidance. As a beginner, it helps me know more about ‘check_env()’ and stable-baselines. I appreciate it very much for your kind help. Best wishes!

1reaction
Miffylicommented, Jul 6, 2020

I meant to say you have to use check_env directly on the environment from gym.make, without the make_vec_env. I.e:

env = gym.make('MyHEM-v0')
check_env(env)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do I get AttributeError: 'NoneType' object has no attribute ...
NoneType means that instead of an instance of whatever Class or Object you think you're working with, you've actually got None .
Read more >
AttributeError: 'NoneType' object has no attribute 'get'
The Python "AttributeError: 'NoneType' object has no attribute 'get'" occurs when we try to call the get() method on a None value, e.g. ......
Read more >
How to fix AttributeError: 'NoneType' object has no attribute 'get'
AttributeError means that there was an Error that had to do with an Attribute request. In general, when you write x.y, y is...
Read more >
How do I fix : attributeerror: 'nonetype' object has no attribute ...
When ever you get a problems that involves a message such as " 'nonetype' object has no attribute ..." it means the same...
Read more >
AttributeError: 'NoneType' object has no ... - Python Forum
The problem is that i get this error: Quote: AttributeError: 'NoneType' object has no attribute 'get'. What i do wrong?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found