Skip to content

Commit

Permalink
Merge pull request #2 from hslu-abiz/refactoring
Browse files Browse the repository at this point in the history
Finished Refactoring
  • Loading branch information
FabianGroeger96 authored Jul 21, 2021
2 parents 5dc1df7 + 3be8ddf commit fe33835
Show file tree
Hide file tree
Showing 33 changed files with 537 additions and 348 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
data
data/*
data/*/*
tmp
tmp/*
profiler
profiler/*
profiler_env/*
core
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.h5 filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Created by https://www.toptal.com/developers/gitignore/api/vim,python,pycharm+all,jupyternotebooks
# Edit at https://www.toptal.com/developers/gitignore?templates=vim,python,pycharm+all,jupyternotebooks

Expand Down Expand Up @@ -277,3 +276,5 @@ extended_prototype/saved_weights/*
extended_prototype/soundbank/*
extended_prototype/soundscapes/*
extended_prototype/test_segmentations/*
saved_weights/*
experiments/*
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM tensorflow/tensorflow:2.4.0-gpu

RUN apt-get update && apt-get install -y apt-transport-https
RUN apt-get install -y libtcmalloc-minimal4
RUN apt-get install -y sox

RUN apt install -y libsndfile1
RUN apt install -y libsm6 libxext6 libxrender-dev

RUN pip install --upgrade pip

WORKDIR /tf

RUN mkdir /assets

COPY requirements.txt /assets/requirements.txt
RUN pip install -r /assets/requirements.txt --upgrade --no-cache-dir

COPY . /tf/

RUN ./scripts/install.sh
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Soundscape Generation

Generate soundscapes from images.

## Table of Contents

1. [Installation](#installation)
Expand All @@ -17,7 +19,7 @@ Follow the instructions give in the following link:

* [Scaper installation](https://scaper.readthedocs.io/en/latest/installation.html)

### Download Dependencies
### Install Dependencies

```bash
pip install -r requirements.txt
Expand All @@ -30,7 +32,7 @@ on [www.cityscapes-dataset.com](https://www.cityscapes-dataset.com/). After the
script. During the download, it will ask you to provide your email and password for authentification.

```bash
./download_data.sh
./scripts/download_data.sh
```

## Usage
Expand All @@ -41,31 +43,35 @@ finetuned on the Cityscapes dataset.

### Train Object Segmentation Network

To train the network, run the follwing command.
To train the network, run the follwing command. The hyperparameters epoch and batch size can be configured in the `docker-compose.yml` file. To load a pre-trained model specify its path in the `MODEL_TO_LOAD` variable, if the variable is `None` the model is trained from scratch.

```bash
python train.py --num_epochs 70 --batch_size 8 --evaluate_every 1 --save_weights_every 1
docker-compose up train_object_detection
```

By default, training resumes from the latest saved checkpoint. If the `checkpoints/` directory is missing, the training
starts from scratch.

### Test the Segmentation Network

Run the following command to predict the semantic segmentation of every image in the `test_images/` directory (note:
results are saved in the `test_segmentations/` directory)
Run the following command to predict the semantic segmentation of every image in the `--test_images` directory (note:
predictions are saved with the same name and a `_pred.jpg` suffix). Ensure that you specify the correct image's file type in `--test_images_type`.

```bash
python predict.py
docker-compose up predict_object_detection
```

Ensure that you specify the image's file type in the image path variable in `predict.py`.
### Evaluate the Segmentation Network
To evaluate the segmentation network run the command below.

```bash
docker-compose up evaluation
```

### Generate soundscapes

Run the file soundGeneration.py to generate soundscapes of every image in the `test_images/` directory (note: results
are saved in the `soundscapes/` directory). Ensure that you specify the image type of the image in the image path
variable of `predict.py`.
To generate soundscapes of every image in the `--test_images` directory run the following command. The generated audios will be saved in `data/soundscapes`. Ensure that you specify the correct image's file type in `--test_images_type`.

```bash
docker-compose up sound_generation
```

## Results

Expand Down
71 changes: 71 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
version: "3.2"
services:
train_object_detection:
build: .
volumes:
- ${PWD}:/tf/
working_dir: /tf
command: bash -c "./scripts/train_object_detection.sh"
devices:
- /dev/nvidia0
environment:
NVIDIA_VISIBLE_DEVICES: 0
EPOCHS: 70
BATCH_SIZE: 8
MODEL_TO_LOAD: None
deploy:
resources:
reservations:
devices:
- capabilities: [ gpu ]

predict_object_detection:
build: .
volumes:
- ${PWD}:/tf/
working_dir: /tf
command: bash -c "./scripts/predict_object_detection.sh"
devices:
- /dev/nvidia0
environment:
NVIDIA_VISIBLE_DEVICES: 0
WEIGHTS_PATH: None
deploy:
resources:
reservations:
devices:
- capabilities: [ gpu ]

sound_generation:
build: .
volumes:
- ${PWD}:/tf/
working_dir: /tf
command: bash -c "./scripts/sound_generation.sh"
devices:
- /dev/nvidia0
environment:
NVIDIA_VISIBLE_DEVICES: 0
WEIGHTS_PATH: None
deploy:
resources:
reservations:
devices:
- capabilities: [ gpu ]

evaluation:
build: .
volumes:
- ${PWD}:/tf/
working_dir: /tf
command: bash -c "./scripts/evaluation.sh"
devices:
- /dev/nvidia0
environment:
NVIDIA_VISIBLE_DEVICES: 0
WEIGHTS_PATH: None
deploy:
resources:
reservations:
devices:
- capabilities: [ gpu ]
3 changes: 3 additions & 0 deletions experiments/Cityscapes/ERFNet-Pretrained/pretrained.h5
Git LFS file not shown
26 changes: 12 additions & 14 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
python==3.8.0
numpy==1.19.5
pandas==1.2.4
scikit-learn==0.24.2
matplotlib==3.4.2
scipy==1.6.3
sox==1.4.0
ffmpeg==4.3.1
ffmpeg-python==0.2.0
numpy
pandas
scikit-learn
matplotlib
scipy
Pillow
sox
ffmpeg
ffmpeg-python
scaper==1.6.5
tensorflow==2.5.0
cudatoolkit==11.0.221
tensorflow-addons==0.13.0
pillow==7.1.2
cityscapesscripts==2.2.0
tensorflow>=2.5.0
tensorflow-addons>=0.13.0
cityscapesscripts==2.2.0
File renamed without changes.
1 change: 1 addition & 0 deletions scripts/evaluation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4 python -m soundscape_generation.evaluation --weights $WEIGHTS_PATH
10 changes: 10 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apt-get update

apt-get -y install git
apt-get -y install libav-tools
apt-get -y install libsndfile1-dev
apt-get -y install libsndfile1
apt-get -y install libcupti-dev

pip install --upgrade pip
pip install -r requirements.txt
1 change: 1 addition & 0 deletions scripts/predict_object_detection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4 python -m soundscape_generation.predict --weights $WEIGHTS_PATH
1 change: 1 addition & 0 deletions scripts/sound_generation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4 python -m soundscape_generation.sound_generation --weights $WEIGHTS_PATH
1 change: 1 addition & 0 deletions scripts/train_object_detection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4 python -m soundscape_generation.train --num_epochs $EPOCHS --batch_size $BATCH_SIZE --model_to_load $MODEL_TO_LOAD
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def parse_requirements(filename):

README_MD = open(join(dirname(abspath(__file__)), "README.md")).read()

setup(name='soundscape-generation',
version=get_version('soundscape-generation/__init__.py'),
setup(name='soundscape_generation',
version=get_version('soundscape_generation/__init__.py'),
author='ABIZ Lab',
author_email='[email protected]',
description='Generate soundscapes based on images.',
Expand Down
47 changes: 0 additions & 47 deletions soundscape-generation/eval/evaluation.py

This file was deleted.

Loading

0 comments on commit fe33835

Please sign in to comment.