Error while rendering in the gym environment - reinforcement-learning

I'm trying to work for a RL project where I need to test the ideas in some Atari environement and I choose Pong to test the initial ideas. I'm using stable-baselines3 version 1.6.2 for ease of convenience. My gym version is 0.21.0. But I'm getting the following error while env.render is called
Exception has occurred: TypeError (note: full exception trace is shown but execution is paused at: _run_module_as_main)
render() takes 1 positional argument but 2 were given
File "/home/s222147455/.conda/envs/new_method/lib/python3.8/site-packages/gym/core.py", line 295, in render
return self.env.render(mode, **kwargs)
File "/home/s222147455/.conda/envs/new_method/lib/python3.8/site-packages/gym/core.py", line 295, in render
return self.env.render(mode, **kwargs)
File "/home/s222147455/.conda/envs/new_method/lib/python3.8/site-packages/gym/core.py", line 295, in render
return self.env.render(mode, **kwargs)
[Previous line repeated 4 more times]
The gym library is wrapped as follows,
env = AtariWrapper(gym.make(args.env), noop_max=30, frame_skip=4, screen_size=84, terminal_on_life_loss=True, clip_reward=False)
env = DummyVecEnv([lambda: env])
env = VecFrameStack(env, n_stack=4, channels_order='first')
I have googled the issue and came to know that there is some mismatch in the gym version. But I couldn't fully resolve the issues

Related

I am getting an error when training yolov5

I am trying to train a yolov5 model, but I'm getting an exception error when I try to execute the training module. The error occurs after the model is loaded and when it tries to read the training images. Below is my code and an excerpt of the error. Any help would be appreciated.
!python train.py --img 640 --batch 16 --epochs 150 --data pollen_data.yaml --weights yolov5x.pt
Model summary: 567 layers, 86217814 parameters, 86217814 gradients, 204.2 GFLOPs
Transferred 739/745 items from yolov5x.pt
Scaled weight_decay = 0.0005
optimizer: SGD with parameter groups 123 weight (no decay), 126 weight, 126 bias
albumentations: version 1.0.3 required by YOLOv5, but version 0.1.12 is currently installed
Traceback (most recent call last):
File "/content/yolov5/utils/datasets.py", line 405, in __init__
t = t.read().strip().splitlines()
File "/usr/lib/python3.7/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "train.py", line 643, in <module>
main(opt)
File "train.py", line 539, in main
train(opt.hyp, opt, device, callbacks)
File "train.py", line 227, in train
prefix=colorstr('train: '), shuffle=True)
File "/content/yolov5/utils/datasets.py", line 110, in create_dataloader
prefix=prefix)
File "/content/yolov5/utils/datasets.py", line 415, in __init__
raise Exception(f'{prefix}Error loading data from {path}: {e}\nSee {HELP_URL}')
Exception: train: Error loading data from /content/datasets/images/training/im0.jpg: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
The training images I have (im0.jpg and im1.jpg) are two large files. The first has dimensions of 9058 x 11185, and the second file is 13385 x 12832. I realize they are not square but I'm assuming that the train.py module will make them square, so it's okay. Is that right?
Or could the non-square dimensions be causing the choke?
Also, what is the meaning of the exception "error loading data from /content/datasets/images/training/im0.jpg: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte"?
Thank you.
I've been using yolov5 for the past 1 month.I must say your error is wierd.
And also, you cant train your model with image size as 12000. By default it should be 640.In your case it might change based on your dataset but i'm quite sure that it wont be 12000.
There is a mistake in your data directory also.
--data /content/datasets/annotations/dataset.yaml.txt
The data file wont have '.txt' extension. It should be a '.yaml' file. SO change that to
--data /content/datasets/annotations/dataset.yaml
It should start training after these changes. If not, close this question and please provide additional information and ask another question.
the error
'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
is raised when you use a image of format which is not mentioned by default.
IMG_FORMATS = 'bmp', 'dng', 'jpeg', 'jpg', 'mpo', 'png', 'tif', 'tiff', 'webp' # include image suffixes
But you have mentioned that it is an jpg. I'm confused now. And also if it helps, pls try this solution provided in this issue. link

dask.delayed KeyError with distributed scheduler

I have a function interpolate_to_particles written in c and wrapped with ctypes. I want to use dask.delayed to make a series of calls to this function.
The code runs successfully without dask
# Interpolate w/o dask
result = interpolate_to_particles(arg1, arg2, arg3)
and with the distributed schedular in single-threaded mode
# Interpolate w/ dask
from dask.distributed import Client
client = Client()
result = dask.delayed(interpolate_to_particles)(arg1, arg2, arg3)
result_c = result.compute(scheduler='single-threaded')
but if I instead call
result_c = result.compute()
I get the following KeyError:
> Traceback (most recent call last): File
> "/path/to/lib/python3.6/site-packages/distributed/worker.py",
> line 3287, in dumps_function
> result = cache_dumps[func] File "/path/to/lib/python3.6/site-packages/distributed/utils.py",
> line 1518, in __getitem__
> value = super().__getitem__(key) File "/path/to/lib/python3.6/collections/__init__.py",
> line 991, in __getitem__
> raise KeyError(key) KeyError: <function interpolate_to_particles at 0x1228ce510>
The worker logs accessed from the dask dashboard do not provide any information. Actually, I do not see any information that the workers have done anything besides starting up.
Any ideas on what could be occurring, or suggested tools that I can use to further debug? Thanks!
Given your comments it sounds like your function does not serialize well. To test this, you might try pickling the function in one process, and try unpickling it in another.
>>> import pickle
>>> print(pickle.dumps(interpolate_to_particles))
b'some bytes printed out here'
And then in another process
>>> import pickle
>>> interpolate_to_particles = pickle.loads(b'the same bytes you had before')
If this doesn't work then you'll know that that's your problem. I would encourage you to look up "how to make sure that ctypes functions are serializable" or something similar, or ask another question with that smaller scope here on Stack Overflow.

Are Explicit Tags in mkdocs config supported in readthedocs?

I've been working on writing some mkdocs documentation which includes mermaid diagrams that I'd like to keep in the markdown files instead of turning into images and embedding them
I came across this great solution here: https://github.com/squidfunk/mkdocs-material/issues/693#issuecomment-411885426
Which uses the super-fences feature of the pymdown-extensions plugin to create a custom code block which renders the mermaid diagrams inside the code block.
It works in mkdocs running locally, but when I submit the configuration file to readthedocs it fails the yaml validation
Your mkdocs.yml could not be loaded, possibly due to a syntax error (line 18, column 19)
Line 18 in the mkdocs.yml config file is the section which calls the superfences python class
format: !!python/name:pymdownx.superfences.fence_div_format
Looking in the yaml specification https://yaml.org/spec/1.2/spec.html Shows that !! is for an explicit tag and it seems to have been part of the spec for quite some time ( back to version 1). I've tried making the value a string but this then causes issue with python reading it as a string
Does anyone know if readthedocs supports this or have you been able to get this working some other way?
ReadTheDocs is parsing the mkdocs.yaml file using pyyaml and it seems that it does not recognize !!.
For example:
>>> import yaml
>>> document = """
a: 1
b:
c: 3
d: !!4
"""
>>> print(yaml.dump(yaml.load(document)))
<stdin>:1: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/site-packages/yaml/__init__.py", line 114, in load
return loader.get_single_data()
File "/usr/lib/python3.8/site-packages/yaml/constructor.py", line 51, in get_single_data
return self.construct_document(node)
File "/usr/lib/python3.8/site-packages/yaml/constructor.py", line 60, in construct_document
for dummy in generator:
File "/usr/lib/python3.8/site-packages/yaml/constructor.py", line 413, in construct_yaml_map
value = self.construct_mapping(node)
File "/usr/lib/python3.8/site-packages/yaml/constructor.py", line 218, in construct_mapping
return super().construct_mapping(node, deep=deep)
File "/usr/lib/python3.8/site-packages/yaml/constructor.py", line 143, in construct_mapping
value = self.construct_object(value_node, deep=deep)
File "/usr/lib/python3.8/site-packages/yaml/constructor.py", line 100, in construct_object
data = constructor(self, node)
File "/usr/lib/python3.8/site-packages/yaml/constructor.py", line 427, in construct_undefined
raise ConstructorError(None, None,
yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:4'
in "<unicode string>", line 5, column 8:
d: !!4
^
>>>
See: https://github.com/readthedocs/readthedocs.org/issues/6889

_mysql_exceptions.OperationalError Freezing wxPython Program

My app is written in Python 2.7 and wxPython 2.8, and accesses a MySQL database. I have had issues with the program freezing when doing an add via:-
cursor.execute(sql ([idSession, TestDateTime, DataBLOb]))
Although this is in try: - except: construct it never executes the except portion. I have run this section from the command line and got:-
_mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')
Obviously I need to investigate the cause of the error but how can I get my software to execute the except: code rather than just freeze!
To solve this, you need to create a new Thread. Look the code:
from threading import Thread
class Spam(wx.Frame):
def doStuff(self, arg1,arg2,arg3)
# Do Something...
try:
cursor.execute(sql ([idSession, TestDateTime, DataBLOb]))
except Exception a e:
# Do the treatments or show a dialog
def ButtonClick(self, event): # Assuming a button like "do this operation"
t = Thread(target=self.doStuff,args=(arg1,arg2,arg3))
t.start()
Observation:
The function doStuff need to be free of errors, if some error raised and not is treated will create a deadlock, or a zombie thread.

Cause of jinja2.exceptions.TemplateNotFound even when using just jinja2

The cause of the problem is obvious after the fact, but I'd like to share the not-too-obvious cause here.
When running code such as
import jinja2
templateLoader = jinja2.FileSystemLoader(searchpath=".")
templateEnv = jinja2.Environment(loader=templateLoader,
trim_blocks=True,
lstrip_blocks=True)
htmlTemplateFile = 'file.jinja.html'
htmlTemplate = templateEnv.get_template(htmlTemplateFile)
if you get this problem:
Traceback (most recent call last):
...
File "file.py", line xyz, in some_func
htmlTemplate = templateEnv.get_template(htmlTemplateFile)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/jinja2/environment.py", line 812, in get_template
return self._load_template(name, self.make_globals(globals))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/jinja2/environment.py", line 774, in _load_template
cache_key = self.loader.get_source(self, name)[1]
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/jinja2/loaders.py", line 187, in get_source
raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: file.jinja.html
you may find the discussions online point that this issue must have something to do with the interaction of jinja2 with flask, with GAE, with Pyramid, or with SQL, and it may indeed be that your templates are not in a "template" folder, but this problem can arise from the interaction of jinja2 and the os module.
The culprit is changing the current directory by, for instance,
import os
os.chdir(someDir)
If templateEnv.get_template(...) is called past this point, jinja2 will look for the templates in the "current" dir, even if that has changed.
Since module os provides os.chdir but not os.pushdir/os.popdir, one has to either simulate the latter pair or avoid chdir altogether.