Skip to content

Commit

Permalink
Gigapixel image support & some error checking (#17)
Browse files Browse the repository at this point in the history
**Bug fixes:**

* The `resize_data.py`, `find_bad.py`, & `vis.py` scripts now support gigapixel images. Hopefully the Pillow/PIL `DecompressionBombWarning` warning no longer shows up. python-pillow/Pillow#515, https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.open You can manually change `Image.MAX_IMAGE_PIXELS = 1000000000` to `Image.MAX_IMAGE_PIXELS = None` if you're still running into issues.

* The `vis.py` script now checks that you specified the required number of image dimensions.


**Improvements:**

* General README improvements for color correlation matrices & color decorrelation.
  • Loading branch information
ProGamerGov authored Nov 6, 2020
1 parent 490f682 commit 84ad998
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ python data_tools/calc_ms.py -data_path <training_data>

Now you can start training your DeepDream model by running the GoogleNet training script. It's recommended that you save the model every 5-10 epochs in order to monitor the quality of the visualizations.

After training your models, you can add a color correlation matrix to them for color decorrelation with the following command:


```
python data_tools/calc_cm.py -data_path <training_data> -model_file <bvlc_out120>.pth
```


---

Expand Down
10 changes: 5 additions & 5 deletions data_tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ All of these scripts with the exception of `sort_images.py` can be copied to and

1. [Dataset Mean and Standard Deviation Calculation](https://github.com/ProGamerGov/dream-creator/tree/master/data_tools#dataset-mean-and-standard-deviation-calculation)

2. [Dataset RGB Covariance Matrix Calculation](https://github.com/ProGamerGov/dream-creator/tree/master/data_tools#dataset-rgb-covariance-matrix-calculation)
2. [Dataset Color Correlation Matrix Calculation](https://github.com/ProGamerGov/dream-creator/tree/master/data_tools#dataset-color-correlation-matrix-calculation)

3. [FC Channel Contents](https://github.com/ProGamerGov/dream-creator/tree/master/data_tools#fc-channel-contents)

Expand All @@ -21,13 +21,13 @@ All of these scripts with the exception of `sort_images.py` can be copied to and

7. [Automatic Image Sorter](https://github.com/ProGamerGov/dream-creator/tree/master/data_tools#automatic-image-sorter)

2. [Model Tools]()
2. [Model Tools](https://github.com/ProGamerGov/dream-creator/tree/master/data_tools#model-editing)

1. [Reduce Model Size](https://github.com/ProGamerGov/dream-creator/tree/master/data_tools#reduce-model-size)

2. [Add/Change Model Values](https://github.com/ProGamerGov/dream-creator/tree/master/data_tools#addchange-model-values)

3. [Visualization & Training Tools]()
3. [Visualization & Training Tools](https://github.com/ProGamerGov/dream-creator/tree/master/data_tools#comparison-of-results)

1. [Graph Training Data](https://github.com/ProGamerGov/dream-creator/tree/master/data_tools#graph-training-data)

Expand All @@ -50,9 +50,9 @@ python calc_ms.py -data_path <training_data>
* `-use_rgb`: Enabling this flag will result in output values being in RGB format instead of BGR.


## Dataset RGB Covariance Matrix Calculation
## Dataset Color Correlation Matrix Calculation

This script calculates the RGB covariance matrix required for color decorrelation.
This script calculates the color correlation matrix required for color decorrelation.

```
python calc_cm.py -data_path <training_data>
Expand Down
2 changes: 2 additions & 0 deletions data_tools/find_bad.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from PIL import Image


Image.MAX_IMAGE_PIXELS = 1000000000 # Support gigapixel images


def main():
parser = argparse.ArgumentParser()
Expand Down
3 changes: 3 additions & 0 deletions data_tools/resize_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from PIL import Image


Image.MAX_IMAGE_PIXELS = 1000000000 # Support gigapixel images


def main():
parser = argparse.ArgumentParser()
parser.add_argument("-data_path", help="Path to your dataset", type=str, default='')
Expand Down
3 changes: 3 additions & 0 deletions utils/vis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from utils.inceptionv1_caffe import InceptionV1_Caffe


Image.MAX_IMAGE_PIXELS = 1000000000 # Support gigapixel images


def calc_image_size(image_path, image_size):
image = Image.open(image_path).convert('RGB')
if type(image_size) is not tuple and type(image_size) is not list or len(image_size) == 1:
Expand Down
3 changes: 3 additions & 0 deletions vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def main():
def main_func(params):
if params.content_image != '':
params.image_size = calc_image_size(params.content_image, params.image_size)
else:
assert len(params.image_size) > 1, "two -image_size values are required when not using a content image"

if params.seed > -1:
set_seed(params.seed)

Expand Down

0 comments on commit 84ad998

Please sign in to comment.