PCGNN - Procedural Content Generation with NEAT and Novelty

Related tags

Deep Learning PCGNN
Overview

PCGNN - Procedural Content Generation with NEAT and Novelty

Generation ApproachMetricsPaperPosterExamples

About

This is a research project for a BSc (Hons) degree at the University of the Witwatersrand, Johannesburg. It's about combining novelty search and NeuroEvolution of Augmenting Topologies (NEAT) for procedural level generation. We also investigate two new metrics for evaluating the diversity and difficulty of levels. This repo contains our code as well as the final report.

If you just want to get started generating or playing levels, then please look at how to generate levels or the examples. Also feel free to look at the report or a poster that summarises our approach. For information about the metrics and how to use them, see here.

General structure

The main structure of the code is (hopefully) somewhat understandable. First of all, to run any python file in here, use ./run.sh path/to/python/file instead of using python directly, because otherwise modules are not recognised.

Most code in here can be categorised into 3 main archetypes:

  1. General / Method code. This is how the methods were actually implemented, and these files don't do anything useful when run on their own.
  2. Runs / Experiment code. This is a large chunk of what is in here, specifically it is code that runs the methods in some way, and generates results. Most of the results that we generate are in python pickle format.
  3. Analysis Code. We have a pretty clear separation between experiment code (which runs the methods), and analysis code, which takes in the results and generates some usable output, like images, tables, graphs, etc.

File Structure

Most of these are relative to ./src

Method Code
├── novelty_neat     -> Our actual method
├── main
├── baselines
├── games
├── common
├── metrics

Instrumental
├── experiments
├── pipelines
├── runs
├── run.sh
├── scripts
└── slurms

Analysis
├── analysis
├── external

Data
├── levels
├── logs
├── results
├── ../results

Document
├── ../doc/report.pdf

Explanation

The method roughly works as follows:

  1. Evolve a neural network using NEAT (with neat-python)
  2. The fitness function for each neural network is as follows:
    1. Generate N levels per network
    2. Calculate the average solvability of these N levels
    3. Calculate how different these N levels are from each other (called intra-novelty). Calculate the average of this.
    4. Calculate how different these N levels are from the other networks' levels (normal novelty)
    5. Fitness (network) = w1 * Solvability + w2 * Intra-Novelty + w3 * Novelty.
  3. Update the networks using the above calculated fitness & repeat for X generations.

After this 'training' process, take the best network and use it to generate levels in real time.

The way novelty is calculated can be found in the report, or from the original paper by Joel Lehman and Kenneth O. Stanley, here.

We compare levels by considering a few different distance functions, like the normalised Hamming Distance and Image Hashing, but others can also be used.

Get started

To get started you would require a python environment, and env.yml is provided to quickly get started with Conda. Use it like: conda create -f env.yml. There is also another environment that is used specifically for interacting with the gym_pcgrl codebase. If that is something you want to do, then create another environment from the env_pcgrl.yml file.

For full functionality, you will also need java installed. The openjdk 16.0.1 2021-04-20 version worked well.

Additionally, most of the actual experiments used Weights & Biases to log experiments and results, so you would also need to log in using your credentials. The simple entry points described below should not require it.

Entry Points

At the moment, the easiest way to interact with the codebase would be to use the code in src/main/.

Generate Levels.

To have a go at generating levels, then you can use the functions provided in src/main/main.py. Specifically you can call this (remember to be in the src directory before running these commands):

./run.sh main/main.py --method noveltyneat --game mario --mode generate --width 114 --height 14

The above allows you to view some generated levels.

Playing Levels

You can also play the (Mario) levels, or let an agent play them. After generating a level using the above, you can play it by using:

./run.sh main/main.py --game mario --command play-human --filename test_level.txt

Or you can let an A* agent play it using

./run.sh main/main.py --game mario --command play-agent --filename test_level.txt

Features

Works for Tilemaps

Mario Mario

Generates arbitrary sized levels without retraining

Mario

Mario-28 Mario-56 Mario-114 Mario-228

Maze



Experiments

We have many different experiments, with the following meaning:

Generalisation - Generate Larger levels

  • v206: Mario
  • v104: Maze NEAT
  • v107: Maze DirectGA

Metrics

  • v202: Mario
  • v106: Maze

Method runs

  • v105: Maze NEAT
  • v102: Maze DirectGA
  • v204: Mario NEAT
  • v201: Mario DirectGA

The PCGRL code can be found in ./src/external/gym-pcgrl

Reproducing

Our results that were shown and mentioned in the report are mainly found in src/results/.

The following describes how to reproduce our results. Note, there might be some difference in the ordering of the images (e.g. mario-level-0.png and mario-level-1.png will swap), but the set of level images generated should be exactly the same.

The whole process contains 3 steps, and does assume a Slurm based cluster scheduler. Please also change the logfile locations (look at running src/pipelines/replace_all_paths.sh from the repository root after changing paths in there - this updates all paths, and decompresses some results). Our partition name was batch, so this also potentially needs to be updated in the Slurm scripts.

You need to run the following three scripts, in order, and before you start the next one, all the jobs from the previous one must have finished.

Note, timing results probably will differ, and for fairness, we recommend using a machine with at least 8 cores, as we do usually run multiple seeds in parallel. Do not continue on to the next step before all runs in the current one have finished. First of all, cd src/pipelines

  1. ./reproduce_full.sh -> Runs the DirectGA & NoveltyNEAT experiments.
  2. ./analyse_all.sh -> Reruns the metric calculations on the above, and saves it to a easy to work with format
  3. ./finalise_analysis.sh -> Uses the above results to create figures and tables.

The analysis runs (steps 2 and 3.) should automatically use the latest results. If you want to change this, then before going from one step to the next, you will need to manually update the location of the .p files, e.g. between step 1. and 2., you need to update

  • src/analysis/proper_experiments/v200/for_mario_generation_1.py,
  • src/analysis/proper_experiments/v100/for_maze_1.py,
  • src/analysis/proper_experiments/v100/analyse_104.py
  • src/analysis/proper_experiments/v200/analyse_206.py.

Likewise, between step 2. and 3., you need to update (only if you don't want to analyse the latest runs.)

  • src/analysis/proper_experiments/v400/analyse_all_statistical_tests.py and
  • src/analysis/proper_experiments/v400/analyse_all_metrics_properly.py.

For PCGRL, the runs do take quite long, so it is suggested to use our models / results. If you really want to rerun the training, you can look at the Slurm scripts in src/slurms/all_pcgrl/*.batch.

For the PCGRL inference, there are two steps to do, specifically:

  1. Run infer_pcgrl.py
  2. Then run the analysis scripts again, specifically analyse_all.sh and finalise_analysis.sh (noting to change the PCGRL filepaths in for_mario_generation_1.py and for_maze_1.py)

Note: The models for turtle (both Mario and Maze) were too large for Github and are thus not included here, but wide is.

Metrics

We also introduce 2 metrics to measure the diversity and difficulty of levels using A* agents. The code for these metrics are in metrics/a_star/a_star_metrics.py.

A* Diversity Metric

The A* diversity metric uses the trajectory of the agent on two levels to evaluate the diversity. Levels that are solved using different paths are marked as diverse, whereas levels with similar paths are marked as similar.

Largely Similar levels

Diversity = 0.08

Left         Right

Different Levels

Diversity = 0.27

Left         Right

All paths

The green and orange paths are quite similar, leading to low diversity

A* Difficulty

This metric measures how much of the search tree of an A* agent needs to be expanded before the agent can solve the level - more expansion indicates more exploration is required and that the level is more difficult.

Left         Right

Applying the metrics code to levels is done in (among others) src/runs/proper_experiments/v300_metrics.

We also experimented with using RL agents to measure the above characteristics, and results looked promising, but the implementation posed some challenges.

Feel free to look in

  • metrics/rl/tabular/rl_agent_metric.py
  • metrics/rl/tabular/tabular_rl_agent.py
  • metrics/rl/tabular/rl_difficulty_metric.py

for this code.

Assorted

Island Models

There is also some code (not thoroughly tested) that uses multiple island populations and performs regular migration between them and these can be found in novelty_neat/mario/test/island_mario.py, novelty_neat/maze/test/island_model.py and src/runs/proper_experiments/v200_mario/v203_island_neat.py.

Other repositories and projects used

These can be found in src/external. We did edit and adapt some of the code, but most of it is still original.

Some ideas from here

And some snippets from Stack Overflow, which I've tried to reference where they were used.

Acknowledgements

This work is based on the research supported wholly by the National Research Foundation of South Africa (Grant UID 133358).

You might also like...
 Boosting Monocular Depth Estimation Models to High-Resolution via Content-Adaptive Multi-Resolution Merging
Boosting Monocular Depth Estimation Models to High-Resolution via Content-Adaptive Multi-Resolution Merging

Boosting Monocular Depth Estimation Models to High-Resolution via Content-Adaptive Multi-Resolution Merging This repository contains an implementation

Official Implementation of CoSMo: Content-Style Modulation for Image Retrieval with Text Feedback
Official Implementation of CoSMo: Content-Style Modulation for Image Retrieval with Text Feedback

CoSMo.pytorch Official Implementation of CoSMo: Content-Style Modulation for Image Retrieval with Text Feedback, Seungmin Lee*, Dongwan Kim*, Bohyung

This script runs neural style transfer against the provided content image.
This script runs neural style transfer against the provided content image.

Neural Style Transfer Content Style Output Description: This script runs neural style transfer against the provided content image. The content image m

Save-restricted-v-3 - Save restricted content Bot For telegram

Save restricted content Bot Contact: Telegram A stable telegram bot to get restr

List of content farm sites like g.penzai.com.

内容农场网站清单 Google 中文搜索结果包含了相当一部分的内容农场式条目,比如「小 X 知识网」「小 X 百科网」。此种链接常会 302 重定向其主站,页面内容为自动生成,大量堆叠关键字,揉杂一些爬取到的内容,完全不具可读性和参考价值。 尤为过分的是,该类网站可能有成千上万个分身域名被 Goog

Python utility to generate filesystem content for Obsidian.
Python utility to generate filesystem content for Obsidian.

Security Vault Generator Quickly parse, format, and output common frameworks/content for Obsidian.md. There is a strong focus on MITRE ATT&CK because

 DeepFaceEditing: Deep Face Generation and Editing with Disentangled Geometry and Appearance Control
DeepFaceEditing: Deep Face Generation and Editing with Disentangled Geometry and Appearance Control

DeepFaceEditing: Deep Face Generation and Editing with Disentangled Geometry and Appearance Control One version of our system is implemented using the

LightSeq is a high performance training and inference library for sequence processing and generation implemented in CUDA Detectron2 is FAIR's next-generation platform for object detection and segmentation.
Detectron2 is FAIR's next-generation platform for object detection and segmentation.

Detectron2 is Facebook AI Research's next generation software system that implements state-of-the-art object detection algorithms. It is a ground-up r

Owner
Michael Beukman
Michael Beukman
[ICCV'21] NEAT: Neural Attention Fields for End-to-End Autonomous Driving

NEAT: Neural Attention Fields for End-to-End Autonomous Driving Paper | Supplementary | Video | Poster | Blog This repository is for the ICCV 2021 pap

null 254 Jan 2, 2023
Flappy bird automation using Neuroevolution of Augmenting Topologies (NEAT) in Python

FlappyAI Flappy bird automation using Neuroevolution of Augmenting Topologies (NEAT) in Python Everything Used Genetic Algorithm especially NEAT conce

Eryawan Presma Y. 2 Mar 24, 2022
The official implementation of the Hybrid Self-Attention NEAT algorithm

PUREPLES - Pure Python Library for ES-HyperNEAT About This is a library of evolutionary algorithms with a focus on neuroevolution, implemented in pure

Adrian Westh 91 Dec 12, 2022
Source code for the GPT-2 story generation models in the EMNLP 2020 paper "STORIUM: A Dataset and Evaluation Platform for Human-in-the-Loop Story Generation"

Storium GPT-2 Models This is the official repository for the GPT-2 models described in the EMNLP 2020 paper [STORIUM: A Dataset and Evaluation Platfor

Nader Akoury 27 Dec 20, 2022
A weakly-supervised scene graph generation codebase. The implementation of our CVPR2021 paper ``Linguistic Structures as Weak Supervision for Visual Scene Graph Generation''

README.md shall be finished soon. WSSGG 0 Overview 1 Installation 1.1 Faster-RCNN 1.2 Language Parser 1.3 GloVe Embeddings 2 Settings 2.1 VG-GT-Graph

Keren Ye 35 Nov 20, 2022
Image-generation-baseline - MUGE Text To Image Generation Baseline

MUGE Text To Image Generation Baseline Requirements and Installation More detail

null 23 Oct 17, 2022
Dungeons and Dragons randomized content generator

Component based Dungeons and Dragons generator Supports Entity/Monster Generation NPC Generation Weapon Generation Encounter Generation Environment Ge

Zac 3 Dec 4, 2021
Pytorch implementation of the paper "Enhancing Content Preservation in Text Style Transfer Using Reverse Attention and Conditional Layer Normalization"

Pytorch implementation of the paper "Enhancing Content Preservation in Text Style Transfer Using Reverse Attention and Conditional Layer Normalization"

Dongkyu Lee 4 Sep 18, 2022
🍷 Gracefully claim weekly free games and monthly content from Epic Store.

EPIC 免费人 ?? 优雅地领取 Epic 免费游戏 Introduction ?? Epic AwesomeGamer 帮助玩家优雅地领取 Epic 免费游戏。 使用 「Epic免费人」可以实现如下需求: get:搬空游戏商店,获取所有常驻免费游戏与免费附加内容; claim:领取周免游戏及其免

null 571 Dec 28, 2022
This Repo is the official CUDA implementation of ICCV 2019 Oral paper for CARAFE: Content-Aware ReAssembly of FEatures

Introduction This Repo is the official CUDA implementation of ICCV 2019 Oral paper for CARAFE: Content-Aware ReAssembly of FEatures. @inproceedings{Wa

Jiaqi Wang 42 Jan 7, 2023