Skip to content

Commit eea611f

Browse files
committed
Initial commit
0 parents  commit eea611f

38 files changed

+694
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
weights.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text

.gitignore

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
model_js
132+
node_modules

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM tensorflow/tensorflow:latest
2+
WORKDIR /usr/src/app
3+
4+
RUN python3 -m pip install -U pip
5+
RUN pip3 install pillow tqdm
6+
RUN apt-get update
7+
RUN apt-get install git git-lfs -y
8+
RUN git clone https://github.com/code2k13/starrem2k13
9+
10+
11+
WORKDIR /usr/src/app/starrem2k13
12+
RUN git-lfs pull
13+
CMD ["bash"]

LICENSE

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

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Star reduction in deep sky images
2+
3+
Starrem2k13 is a simple and easy tool to remove stars from astronomical images. Starrem2k13 uses a GAN trained on augmented data. Code was inspired from a [sample at Tensorflow's website](https://www.tensorflow.org/tutorials/generative/pix2pix). The training data consists of only two images. One image of the Helix nebula and another is a starmap that was created from a star cluster image. Here is how the results look like:
4+
5+
![images/example2.png](images/example2.jpg)
6+
7+
![images/example.png](images/example.jpg)
8+
9+
10+
# Installing
11+
Currently binaries for Windows, Linux and MacOS are available in the releases section. These were created using PyInstaller. Using pre-complied binaries is the recommended way of running Starrem2k13. Once you have downloaded and installed the program you can run it simply by typing the following in command prompt/terminal
12+
13+
Run inference on image.
14+
```shell
15+
starrem2k13 image_with_stars.jpg image_without_stars.jpg
16+
```
17+
18+
## Running using Docker (Recommended)
19+
20+
```
21+
docker run -v $PWD:/usr/src/app/starrem2k13/data \
22+
-it code2k13/starrem2k13 \
23+
/bin/bash -c "./starrem2k13.py ./data/example.jpg ./data/example_starless.jpg"
24+
```
25+
Note that *$PWD* refers to your current working directory. In the above example it is assumed that the file *example.jpg* resides in your current working directory. This directory is mounted as a volume with the path */usr/src/app/starrem2k13/data* inside the docker container. The output image *example_starless.jpg* will also be written to same directory.
26+
27+
28+
## Running with local python installation
29+
Clone the repository and navigate to the 'starrem2k13' folder. Install required packages :
30+
31+
```shell
32+
pip install -r requirements.txt
33+
```
34+
35+
Additionally you may also have to install lfs support for git
36+
```
37+
git clone https://github.com/code2k13/starrem2k13.git
38+
cd starrem2k13
39+
sudo apt-get install git-lfs
40+
git lfs pull
41+
```
42+
43+
Run inference on image.
44+
```shell
45+
python starrem2k13.py image_with_stars.jpg image_without_stars.jpg
46+
```
47+
48+
> Supprots greyscale and RGB images. Alpha channel (if any) in the source image is removed during processing. Gives issues on some types of TIFF files.
49+
50+
51+
## Trying out the model in a web browser
52+
Here is link to a online demo of star reduction created using a trained model, TFJS and ReactJS. Please use a **desktop browser** to access the demo (for memory and performance reasons). The demo runs locally inside your browser, no data outside of your computer. Here is the link to the demo : https://ashishware.com/static/star_removal/index.html
53+
54+
![](https://ashishware.com/images/star_removal_demo1.jpg)
55+
56+
## Training model on your images
57+
58+
The [notebook](train/star-removal-from-astronomical-images-with-pix2pix.ipynb) is available in the train folder.
59+
60+
You can also view/run it on Kaggle:
61+
[https://www.kaggle.com/finalepoch/star-removal-from-astronomical-images-with-pix2pix](https://www.kaggle.com/finalepoch/star-removal-from-astronomical-images-with-pix2pix)
62+
63+
64+
## Attribution
65+
66+
The training images used in this code were sourced from Wikimedia Commons and processed using GIMP.
67+
68+
### Antennae Galaxy Image
69+
This image was downloaded from Wikimedia Commons and converted to grayscale using GIMP by me for purpose of training the model.
70+
71+
Link to processed image: [training_data/Antennae_galaxies_xl.png](training_data/Antennae_galaxies_xl.png)
72+
73+
>[NASA, ESA, and the Hubble Heritage Team (STScI/AURA)-ESA/Hubble Collaboration](https://commons.wikimedia.org/wiki/File:Antennae_galaxies_xl.jpg), Public domain, via Wikimedia Commons
74+
75+
Url : [https://commons.wikimedia.org/wiki/File:Antennae_galaxies_xl.jpg](https://commons.wikimedia.org/wiki/File:Antennae_galaxies_xl.jpg)
76+
77+
Direct Link: [https://upload.wikimedia.org/wikipedia/commons/f/f6/Antennae_galaxies_xl.jpg](https://upload.wikimedia.org/wikipedia/commons/f/f6/Antennae_galaxies_xl.jpg)
78+
79+
80+
81+
### Star cluster NGC 3572 and its surroundings
82+
This image was downloaded from Wikimedia Commons and star mask was created by me using GIMP
83+
84+
Link to the processed image: [training_data/star_map_base.png](training_data/star_map_base.png)
85+
86+
> [ESO/G. Beccari, CC BY 4.0](https://creativecommons.org/licenses/by/4.0), via Wikimedia Commons
87+
88+
Url: [https://commons.wikimedia.org/wiki/File:The_star_cluster_NGC_3572_and_its_dramatic_surroundings.jpg](https://commons.wikimedia.org/wiki/File:The_star_cluster_NGC_3572_and_its_dramatic_surroundings.jpg)
89+
90+
Direct Link: [https://upload.wikimedia.org/wikipedia/commons/9/95/The_star_cluster_NGC_3572_and_its_dramatic_surroundings.jpg](https://upload.wikimedia.org/wikipedia/commons/9/95/The_star_cluster_NGC_3572_and_its_dramatic_surroundings.jpg)
91+
92+
93+

batch_process.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
for file in samples/*.jpg
2+
do
3+
python starrem2k13.py "$file" "samples_starless/${file##*/}"
4+
done

convert_model.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import tensorflow as tf
2+
import model
3+
import tensorflowjs as tfjs
4+
5+
G2 = model.Generator()
6+
G2.trainable = False
7+
G2.load_weights("weights/weights")
8+
9+
# Convert the model
10+
converter = tf.lite.TFLiteConverter.from_keras_model(G2) # path to the SavedModel directory
11+
#converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_LATENCY]
12+
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
13+
tflite_model = converter.convert()
14+
15+
# Save the model.
16+
with open('model.tflite', 'wb') as f:
17+
f.write(tflite_model)
18+
19+
tfjs.converters.save_keras_model(G2, "model_js")
2.69 KB
Loading

0 commit comments

Comments
 (0)