Skip to content

Commit 7528c8f

Browse files
authored
Merge pull request #53 from valentingol/reorganize_repo
🆙 Update to 2.2.0
2 parents 66e4e56 + 089377b commit 7528c8f

File tree

85 files changed

+610
-268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+610
-268
lines changed

.github/workflows/pydocstyle.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
run: |
2424
n_errors=$(wc -l < pydocstyle.txt)
2525
echo "Number of errors in docstrings: $n_errors"
26-
python utils/github_actions/pydocstyle_manager.py --n_errors=$n_errors
26+
python github_actions/pydocstyle_manager.py --n_errors=$n_errors

.github/workflows/pylint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
run: |
2424
score=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' .pylint.txt)
2525
echo "Pylint score was $score"
26-
color=$(python utils/github_actions/pylint_manager.py --score=$score --score_min=8.0)
26+
color=$(python github_actions/pylint_manager.py --score=$score --score_min=8.0)
2727
echo "PYLINT_COLOR=$color"
2828
echo "PYLINT_COLOR=$color" >> $GITHUB_ENV
2929
echo "PYLINT_SCORE=$score/10.00"

README.md

Lines changed: 115 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,54 @@
11
# Facies modeling with GANs
22

3-
Underground facies (= kind of rocks) modeling with GANs.
3+
Underground facies (= kind of sediment) modeling with GANs.
4+
5+
**Disclaimer**: This repository is a work in progress. This code aims to be the
6+
official implementation of a not already published research paper. It provides
7+
a complete code to train and evaluate some GANs for facies modeling as well as
8+
unit tests and a small ready-to-use dataset (see below).
49

510
![PythonVersion](https://img.shields.io/badge/python-3.7%20%7E%203.10-informational)
611
![PytorchVersion](https://img.shields.io/badge/Pytorch-1.8%20%7E%201.12-blue)
7-
[![License](https://img.shields.io/badge/license-MIT-white)](https://stringfixer.com/fr/MIT_license)
12+
[![License](https://img.shields.io/badge/license-MIT-white)](
13+
https://stringfixer.com/fr/MIT_license)
814
![WandB](https://img.shields.io/badge/WandB-supported-brightgreen)
915
![ClearML](https://img.shields.io/badge/ClearML-supported-brightgreen)
1016

11-
[![Flake8](https://github.com/valentingol/gan-facies-modeling/actions/workflows/flake.yaml/badge.svg)](https://github.com/valentingol/gan-facies-modeling/actions/workflows/flake.yaml)
12-
[![Pydocstyle](https://github.com/valentingol/gan-facies-modeling/actions/workflows/pydocstyle.yaml/badge.svg)](https://github.com/valentingol/gan-facies-modeling/actions/workflows/pydocstyle.yaml)
13-
[![MyPy](https://github.com/valentingol/gan-facies-modeling/actions/workflows/mypy.yaml/badge.svg)](https://github.com/valentingol/gan-facies-modeling/actions/workflows/mypy.yaml)
14-
[![Isort](https://github.com/valentingol/gan-facies-modeling/actions/workflows/isort.yaml/badge.svg)](https://github.com/valentingol/gan-facies-modeling/actions/workflows/isort.yaml)
15-
[![PyLint](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/valentingol/106c646ac67294657bccf02bbe22208f/raw/gan_facies_modeling_pylint.json)](https://github.com/valentingol/gan-facies-modeling/actions/workflows/pylint.yaml)
17+
[![Flake8](
18+
https://github.com/valentingol/gan-facies-modeling/actions/workflows/flake.yaml/badge.svg)](
19+
https://github.com/valentingol/gan-facies-modeling/actions/workflows/flake.yaml)
20+
[![Pydocstyle](
21+
https://github.com/valentingol/gan-facies-modeling/actions/workflows/pydocstyle.yaml/badge.svg)](
22+
https://github.com/valentingol/gan-facies-modeling/actions/workflows/pydocstyle.yaml)
23+
[![MyPy](
24+
https://github.com/valentingol/gan-facies-modeling/actions/workflows/mypy.yaml/badge.svg)](
25+
https://github.com/valentingol/gan-facies-modeling/actions/workflows/mypy.yaml)
26+
[![Isort](
27+
https://github.com/valentingol/gan-facies-modeling/actions/workflows/isort.yaml/badge.svg)](
28+
https://github.com/valentingol/gan-facies-modeling/actions/workflows/isort.yaml)
29+
[![PyLint](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/valentingol/106c646ac67294657bccf02bbe22208f/raw/gan_facies_modeling_pylint.json)](
30+
https://github.com/valentingol/gan-facies-modeling/actions/workflows/pylint.yaml)
1631

1732
---
1833

1934
Date: 2022-07-20
2035

2136
Author: [github@Valentingol](https://github.com/valentingol)
2237

38+
[![GitHub User followers](
39+
https://img.shields.io/github/followers/valentingol?label=Owner%20followers&style=social)](
40+
https://github.com/valentingol)
41+
[![GitHub User's User stars](
42+
https://img.shields.io/github/stars/valentingol?label=Owner%20Stars&style=social)](
43+
https://github.com/valentingol)
44+
2345
Work during my 5 months internship at [IFPEN](https://www.ifpenergiesnouvelles.com/),
2446
supervised by [UVSQ](https://www.uvsq.fr/english)
2547
and financed by [DATAIA Paris Saclay](https://dataia.eu/en/dataia-paris-saclay-institute).
2648

27-
[![GitHub User followers](https://img.shields.io/github/followers/valentingol?label=Owner%20followers&style=social)](https://github.com/valentingol)
28-
[![GitHub User's User stars](https://img.shields.io/github/stars/valentingol?label=Owner%20Stars&style=social)](https://github.com/valentingol)
49+
Copyright © 2022 Goldite Valentin
50+
51+
MIT License ([see here](LICENSE.md))
2952

3053
---
3154

@@ -35,40 +58,22 @@ and financed by [DATAIA Paris Saclay](https://dataia.eu/en/dataia-paris-saclay-i
3558

3659
- `sagan` - Unconditional SAGAN (based on
3760
[Self-Attention Generative Adversarial Networks](https://arxiv.org/abs/1805.08318)
38-
and [Modeling of subsurface sedimentary facies using SAGANs](https://www.sciencedirect.com/science/article/abs/pii/S0920410522003540))
61+
and [Modeling of subsurface sedimentary facies using SAGANs](
62+
https://www.sciencedirect.com/science/article/abs/pii/S0920410522003540))
3963

4064
- `cond_sagan` - Conditional SAGAN (based on
4165
papers above
4266
for SAGAN part and
43-
[GANSim: Conditional Facies Simulation Using an Improved Progressive Growing of GANS](https://ideas.repec.org/p/osf/eartha/fm24b.html)
44-
for conditional part)
67+
[GANSim: Conditional Facies Simulation Using an Improved Progressive Growing of GANS](
68+
https://ideas.repec.org/p/osf/eartha/fm24b.html)
69+
for conditional part) that also reconstructs input pixel maps
70+
71+
Note that you can disable self-attention in the configurations (DCGAN architecture).
4572

4673
**3D Models:**
4774

4875
- soon 🚧
4976

50-
## Examples
51-
52-
### GANSim dataset
53-
54-
| <img src="./assets/images/gansim_real.png" width="512">
55-
|:--:|
56-
| **Real Images** (64 $\times$ 64)|
57-
58-
| <img src="./assets/images/gansim_generated.png" width="512">
59-
|:--:|
60-
| **Generated Images** (128 $\times$ 128)|
61-
62-
### Stanford-VI dataset (first part)
63-
64-
| <img src="./assets/images/stanfordp1_real.png" width="512">
65-
|:--:|
66-
| **Real Images**|
67-
68-
| <img src="./assets/images/stanfordp1_generated.png" width="512">
69-
|:--:|
70-
| **Generated Images**|
71-
7277
## Quick start
7378

7479
### Installation
@@ -78,78 +83,95 @@ Install the module and dependencies in a virtual environment with Python 3.7-3.1
7883
```bash
7984
pip install -e .
8085
pip install -r requirements.txt
81-
# for dev only:
86+
# for developers only:
8287
pip install -r requirements-dev.txt
8388
```
8489

85-
### Train on a dataset
90+
### Train on the default dataset
8691

8792
A small dataset is available by default in this repository. It contains 2000
8893
synthesized images representing some channels and 3 kind of facies and was
8994
generated in the [GANSim project](https://github.com/SuihongSong/GeoModeling_GANSim-2D_Condition_to_Well_Facies_and_Global_Features)
9095
(under [MIT license](./assets/third_party_licenses/GANSim%20MIT%20LICENSE)).
9196
More synthesized data are available
92-
[here](https://zenodo.org/record/3993791#.X1FQuMhKhaR).
97+
[here](https://zenodo.org/record/3993791#.X1FQuMhKhaR). **If you use this dataset
98+
in your work, please cite the original authors.**
9399

94-
Of course, you can put your own dataset in the `datasets` folder. The dataset
95-
should be a Numpy (`.npy`) file containing a 3D ndarray with format
96-
(z/depth/n_samples, y, x) of type `uint8` with a different number for each
97-
facies, starting from 0. The number of facies is then `dataset.max() + 1`.
98-
99-
Now you can simply run a train on the default dataset with unconditional SAGAN
100-
model using the following command:
100+
You can simply run a train on the default dataset with unconditional SAGAN
101+
model using the following command in `gan_facies` folder:
101102

102103
```bash
103-
python apps/train.py
104+
python gan_facies/apps/train.py
104105
```
105106

106107
You can see the progress of the training in the terminal and the resulted
107108
images and trained networks in the `res` folder.
108109

109-
This repository contains a lot of configurations to customize the training and
110-
will be explained in the next section.
110+
## Use your own dataset
111+
112+
Of course, you can use your own dataset. Simply drop it in the `datasets` folder.
113+
The dataset should be a Numpy file (`.npy`) containing a 3D ndarray with format
114+
(z/depth/n_samples, y, x) of type `uint8` with a different number for each
115+
facies, starting from 0. The number of facies is then `dataset.max() + 1`.
116+
Now tou can run the training adding the `--dataset_path=<mypath>` argument.
117+
You can also change the dataset path via configuration files. The next section
118+
explains how to do that.
111119

112120
## Configurations
113121

114-
Of course it is always interesting to customize the training with flexibility.
115-
Thus this repository use the smart configuration manager
116-
[YAECS](https://github.com/valentingol/yaecs).
122+
It is always interesting to customize the training with your own configurations.
123+
This repository contains a lot of configuration organized in multiple sub-configurations.
124+
The management of the configurations is simply done thanks to the smart configuration
125+
manager [YAECS](https://github.com/valentingol/yaecs).
117126

118127
The default sub-configurations (for models, training, ...) are organized in
119-
different sub-folders in `configs/default`. You can launch an experiment by
120-
writing an other configuration `.yaml` file that will be merged with the
121-
default one. Some examples are available in `configs/exp`. For example,
122-
this will override the default value of the name of the run and discriminator
128+
different json files in `configs/default`. You can launch your own experiment by
129+
writing a new `.yaml` file that will be merged with the default configuration.
130+
Some examples are available in `configs/exp`. For example, the following file
131+
will override the default value of the name of the run as well as discriminator
123132
learning rate to 0.001:
124133

125134
```yaml
126-
# configs/exp/my_experiment.yaml
135+
# >> file 'configs/exp/my_config.yaml'
127136
run_name: my_experiment
128137
training.d_lr: 0.001
129138
```
130139
131140
Then you can run the experiment by adding the configuration in command line.
132141
133142
```bash
134-
python apps/train.py --config configs/exp/my_config.yaml
143+
python gan_facies/apps/train.py --config gan_facies/configs/exp/my_config.yaml
135144
```
136145

137146
*Note: The space between the `--config` and the configuration file is important.*
138147

139-
You can also put instead a **list** of configuration paths to merge together
140-
several experiment files (from the begin of the list to the end).
141-
142148
Moreover you can override parameters also by adding them in the **command line**.
143149
For example this will override the default configuration with your experiment
144150
configuration, then set the generator learning rate to 0.001 and the generator
145151
random input dimension to 64:
146152

147153
```bash
148-
python apps/train.py --config configs/exp/my_config.yaml --training.g_lr=0.001 --model.z_dim=64
154+
python gan_facies/apps/train.py --config gan_facies/configs/exp/my_config.yaml--training.g_lr=0.001\
155+
--model.z_dim=64
149156
```
150157

151158
*Note: The `=` between the `--param` and the value is important.*
152159

160+
To use conditional model you can check the `configs/exp/conditional.yaml` file
161+
and adapt it to your needs. An other way is to use the merging of configurations
162+
in cascade provided by yaecs. In fact, if you can put **list** of configuration
163+
file for `--configs`, they will be merge together (from the begin of the list
164+
to the end). Example:
165+
166+
```batch
167+
python gan_facies/apps/train.py --config [gan_facies/configs/exp/models/cond_sagan.yaml,gan_facies/configs/exp/my_config.yaml]
168+
```
169+
170+
First `configs/exp/models/cond_sagan.yaml` will be merged (changing model configuration)
171+
then `configs/exp/my_config` (overwriting model configuration if needed).
172+
You can create your own specific configurations (for data, models, metric, ...)
173+
and merge as many of them as you want.
174+
153175
Finally, the configurations will be automatically saved (by default in `res/configs`)
154176
to ensure that you can always recover the exact configuration used for the runs.
155177
The "hierarchy of merging" is also saved to understand quickly how the configuration
@@ -165,11 +187,11 @@ more interesting parameters and many utilities to explore parameters space
165187
(collaboratively or not), etc.
166188

167189
This repository allows to use WandB and ClearML very simply. You can check the default
168-
configuration implying WandB in `configs/default/wandb.yaml` and ClearML in
169-
`configs/default/clearml.yaml`. To use Wandb or ClearML you need to install
170-
one of them, create an account if you don't have one and set the configuration
171-
`wandb.use_wandb: True` or `clearml.use_clearml: True` in addition to the parameters
172-
for initialize the WandB run or ClearML task.
190+
configuration implying WandB and ClearML in `configs/default/experiment_tracking.yaml`.
191+
To use Wandb or ClearML you first need to install them, create an account if
192+
you don't have one and set the configuration `wandb.use_wandb: True` or
193+
`clearml.use_clearml: True` in addition to the parameters for initialize
194+
the WandB run or ClearML task.
173195

174196
Plus, you can explore the parameters space using `wandb.sweep`. To do so, you
175197
simply need to create a sweep config such as in `configs/sweep/ex_sweep.yaml`
@@ -181,18 +203,42 @@ in `configs/exp`.
181203
Note:
182204

183205
- It is currently not possible to use both ClearML and WandB at the same time
184-
- It is currently not possible to use hyperparameter search with ClearML in
185-
this repository (🚧)
206+
- It is currently not possible to use hyperparameter search with ClearML
207+
(only with wandb sweep). But we welcome any contribution to add this feature
208+
(see [`CONTRIBUTE.md`](CONTRIBUTE.md))
209+
210+
## Examples of generated images
211+
212+
### GANSim dataset
213+
214+
| <img src="./assets/images/gansim_real.png" width="512">
215+
|:--:|
216+
| **Real Images** (64 $\times$ 64)|
217+
218+
| <img src="./assets/images/gansim_generated.png" width="512">
219+
|:--:|
220+
| **Generated Images** (128 $\times$ 128)|
221+
222+
### Stanford-VI dataset (first part)
223+
224+
| <img src="./assets/images/stanfordp1_real.png" width="512">
225+
|:--:|
226+
| **Real Images**|
227+
228+
| <img src="./assets/images/stanfordp1_generated.png" width="512">
229+
|:--:|
230+
| **Generated Images**|
186231

187232
## TODO list
188233

189234
- [x] Add test for generator in `apps/train.py`
190235
- [x] Add generated results on GANSim dataset and
191236
[Stanford VI dataset](https://github.com/SCRFpublic/Stanford-VI-E/tree/master/Facies)
192237
- [x] Add conditional SAGAN
238+
- [ ] Add images generated by conditional model and metrics in README
193239
- [ ] Add 3D models
194-
- [ ] Explore other architectures
195240

196241
## How to contribute
197242

198-
Please have a look on [CONTRIBUTE.md](./CONTRIBUTE.md). Thank you very much! 🙏
243+
We welcome any contribution to improve this repository. Please have a look on
244+
[CONTRIBUTE.md](./CONTRIBUTE.md). Thank you very much! 🙏

gan_facies/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""GAN facies modeling repository..
2+
3+
MIT License
4+
5+
Copyright (c) 2022 Goldite Valentin
6+
7+
Permission is hereby granted, free of charge, to any person obtaining
8+
a copy of this software and associated documentation files
9+
(the "Software"), to deal in the Software without restriction,
10+
including without limitation the rights to use, copy, modify, merge,
11+
publish, distribute, sublicense, and/or sell copies of the Software,
12+
and to permit persons to whom the Software is furnished to do so,
13+
subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included
16+
in all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24+
DEALINGS IN THE SOFTWARE.
25+
"""

apps/eval.py renamed to gan_facies/apps/eval.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
from PIL import Image
1010
from thop import profile
1111

12-
from utils.auxiliaries import set_global_seed
13-
from utils.conditioning import colorize_pixel_map, generate_pixel_maps
14-
from utils.configs import ConfigType, GlobalConfig
15-
from utils.data.data_loader import DatasetCond2D, DistributedDataLoader
16-
from utils.data.process import to_img_grid
17-
from utils.gan.cond_sagan.modules import CondSAGenerator
18-
from utils.gan.uncond_sagan.modules import UncondSAGenerator
19-
from utils.metrics import compute_save_indicators, evaluate, print_metrics
12+
from gan_facies.data.data_loader import DatasetCond2D, DistributedDataLoader
13+
from gan_facies.data.process import to_img_grid
14+
from gan_facies.gan.cond_sagan.modules import CondSAGenerator
15+
from gan_facies.gan.uncond_sagan.modules import UncondSAGenerator
16+
from gan_facies.metrics import compute_save_indicators, evaluate, print_metrics
17+
from gan_facies.utils.auxiliaries import set_global_seed
18+
from gan_facies.utils.conditioning import (colorize_pixel_map,
19+
generate_pixel_maps)
20+
from gan_facies.utils.configs import ConfigType, GlobalConfig
2021

2122

2223
def test(config: ConfigType) -> None:
@@ -87,7 +88,7 @@ def test(config: ConfigType) -> None:
8788
with torch.no_grad():
8889
images, attn_list = generator.generate(z_input, with_attn=True)
8990
# pylint: disable=unbalanced-tuple-unpacking
90-
macs, _ = profile(generator, inputs=(z_input, pixel_maps))
91+
macs, _ = profile(generator, inputs=(z_input,))
9192

9293
# Save and show sample images in a grid
9394
img_out_dir = osp.join(config.output_dir, config.run_name, 'samples')
@@ -133,6 +134,6 @@ def save_and_show(image: Optional[np.ndarray], path: str) -> None:
133134

134135
if __name__ == '__main__':
135136
global_config = GlobalConfig.build_from_argv(
136-
fallback='configs/exp/base.yaml')
137+
fallback='gan_facies/configs/exp/base.yaml')
137138
# NOTE: The config is not saved when testing only
138139
test(global_config)

apps/tools/compute_ref_metrics.py renamed to gan_facies/apps/tools/compute_ref_metrics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import numpy as np
44

5-
from utils.configs import GlobalConfig
6-
from utils.metrics import print_metrics
7-
from utils.metrics.metric import wasserstein_distances
5+
from gan_facies.metrics import print_metrics
6+
from gan_facies.metrics.metric import wasserstein_distances
7+
from gan_facies.utils.configs import GlobalConfig
88

99
if __name__ == '__main__':
1010
global_config = GlobalConfig.build_from_argv(
11-
fallback='configs/exp/base.yaml')
11+
fallback='gan_facies/configs/exp/base.yaml')
1212
data = np.load(global_config.dataset_path)
1313
data1 = data[:len(data) // 2][:5000]
1414
data2 = data[len(data) // 2:][:5000]

0 commit comments

Comments
 (0)