Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature detectors for MineRL #22

Merged
merged 3 commits into from
Jul 28, 2021
Merged

Conversation

jadeoneill
Copy link
Contributor

Adds a simple & efficient computer vision system for Minecraft, and features for compass angle and reward. There is documentation in rocca/envs/wrappers/utils.py

…dable by the pattern miner. Secondly, add a simple and efficient computer vision function.
Comment on lines 27 to 89
last_compassAngle = None
def convert_percept(predicate, *args):
"""Firstly, the MineRL environment gives us a different floating point
reward number every step. This function converts it into +1 or -1 so that
the pattern miner can find frequent patterns involving reward.

Secondly, MineRL gives us a 2D image of the agent's view within Minecraft,
but this function gives the agent the average location of each approximate
color on screen. The colors are put in bins of 20 pixel brightness values,
and then we record the average location of the color bin on screen. Note
that this function doesn't divide the screen into blobs of one color; it
may find the average of multiple blobs of one color. Note that the pattern
miner will still have difficulty with this feature so it's a work in
progress.

Thirdly, MineRL gives us the angle between the agent and the goal (compassAngle).
This function creates a boolean predicate for whether the angle has got closer
or not."""
if predicate == "pov":
#print (args, type(args))
#args = ["some image"]
from collections import defaultdict
colors = defaultdict(list)

for y in range(0, 64):
for x in range(0, 64):
color = args[y][x]
rounded_color = tuple([subpixel // 25 * 25 for subpixel in color])
colors[rounded_color].append((x, y))

#print(f"{len(colors.keys())} colors in this frame")
#args = ["some image"]
links = []
for (color, locations) in colors.items():
total_x = total_y = 0
for (x, y) in locations:
total_x += x
total_y += y
links.append(AtLocationLink(mk_node("color:"+str(color)), mk_node("viewLocation:"+str((total_x//len(locations), total_y//len(locations))))))
#print(links)
return links

elif predicate == "Reward":
if float(args[0]) > 0:
args = [1]
elif float(args[0]) < 0:
args = [-1]

elif predicate == "compassAngle":
global last_compassAngle
lca = last_compassAngle
current = float(args[0])
links = []

if not lca is None:
if abs(0 - current) < abs(0 - lca):
links = [mk_evaluation("compassAngleCloser")]
print(links)

last_compassAngle = current
return links

return [mk_evaluation(predicate, *args)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not track state as a global variable in a module - it would probably be best if you create a derived class from OpencogAgent (or modify NavigateAgent) such that the compass is tracked via an object field. Similarly, this function probably would fit better as a method of such class instead of a free-floating utility one.

@jadeoneill
Copy link
Contributor Author

jadeoneill commented Jul 16, 2021 via email

@ntoxeg
Copy link
Contributor

ntoxeg commented Jul 16, 2021

Hi, because convert_percept is called from GymWrapper I created a subclass called MineRLWrapper that contains the function and the variable. I couldn't put it in NavigateAgent because GymWrapper objects don't have access to the OpencogAgent object.

Right, makes sense.

Copy link
Contributor

@ntoxeg ntoxeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For 02_minerl_navigate_agent.ipynb (and working with notebooks in general) please remember to run nbstripout to get rid of unnecessary metadata changes. You can setup a git hook to do this automatically before committing.

@jadeoneill
Copy link
Contributor Author

jadeoneill commented Jul 19, 2021 via email

@ntoxeg
Copy link
Contributor

ntoxeg commented Jul 19, 2021

Ok, it looks like something is not right but we will fix this later on if needed. Otherwise, it looks good @jadeoneill

@ngeiswei ngeiswei merged commit 45ae155 into opencog:master Jul 28, 2021
@ngeiswei
Copy link
Member

Thanks @jadeoneill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants