Running Starnet2/Starnet++ with GPU on Linux

Remove stars from your astro pictures

StarNet (https://www.starnetastro.com/) has become the de-facto star reduction software of choice for astrophotography. Its purpose is to remove stars from the pictures, so you can focus on treating the background that require different settings than the stars. StarNet++ works pretty well on Linux (as a CLI application) but the executable does not support CUDA and GPU acceleration by default, making it a bit slow.

I found this tutorial that explains how to GPU-enable StarNet on Windows: https://www.williamliphotos.com/starnet-cuda. Let’s do the same on Linux. I am using Ubuntu 22.04.1 with an nVidia RTX 2080 SUPER.

First, download the CLI version of Starnet and extract it, if it’s not done yet. create a tf directory where we will link the important files:

aris@starkiller:~/astro/StarNetv2CLI_linux$ mkdir tf
aris@starkiller:~/astro/StarNetv2CLI_linux$ cd tf
aris@starkiller:~/astro/StarNetv2CLI_linux/tf$ ln -s ../libtiff.so.3 ../starnet++ ../starnet2_weights.pb .
aris@starkiller:~/astro/StarNetv2CLI_linux/tf$

Now you need to install the GPU-enabled version of tensorflow and the CUDA libraries.

Download TensorFlow from https://www.tensorflow.org/install/lang_c?hl=en and choose “Linux GPU support”. In my case, I used this link.

aris@starkiller:~/astro/StarNetv2CLI_linux/tf$ wget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-2.9.1.tar.gz
--2022-09-02 18:30:49-- https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-2.9.1.tar.gz
Résolution de storage.googleapis.com (storage.googleapis.com)… 216.58.214.16, 142.250.179.208, 216.58.208.112, …
Connexion à storage.googleapis.com (storage.googleapis.com)|216.58.214.16|:443… connecté.
requête HTTP transmise, en attente de la réponse… 200 OK
Taille : 411473058 (392M) [application/x-tar]
Enregistre : ‘libtensorflow-gpu-linux-x86_64-2.9.1.tar.gz’

libtensorflow-gpu-linux-x86_64- 100%[====================================================>] 392,41M 39,8MB/s ds 9,7s

2022-09-02 18:31:00 (40,2 MB/s) - ‘libtensorflow-gpu-linux-x86_64-2.9.1.tar.gz’ enregistré [411473058/411473058]
aris@starkiller:~/astro/StarNetv2CLI_linux/tf$ tar xzfv libtensorflow-gpu-linux-x86_64-2.9.1.tar.gz
./
./include/
./include/tensorflow/
./include/tensorflow/c/
./include/tensorflow/c/c_api.h
./include/tensorflow/c/c_api_experimental.h
./include/tensorflow/c/c_api_macros.h
./include/tensorflow/c/tensor_interface.h
./include/tensorflow/c/tf_attrtype.h
./include/tensorflow/c/tf_datatype.h
./include/tensorflow/c/tf_file_statistics.h
./include/tensorflow/c/tf_status.h
./include/tensorflow/c/tf_tensor.h
./include/tensorflow/c/tf_tstring.h
./include/tensorflow/core/
./include/tensorflow/core/platform/
./include/tensorflow/core/platform/ctstring.h
./include/tensorflow/core/platform/ctstring_internal.h
./include/tensorflow/compiler/
./include/tensorflow/compiler/tf2tensorrt/
./include/tensorflow/compiler/tf2tensorrt/trt_convert_api.h
./lib/
./lib/libtensorflow.so.2.9.1
./lib/libtensorflow_framework.so.2.9.1
./lib/libtensorflow_framework.so
./lib/libtensorflow_framework.so.2
./lib/libtensorflow.so
./lib/libtensorflow.so.2
./THIRD_PARTY_TF_C_LICENSES
./LICENSE
./include/tensorflow/c/eager/
./include/tensorflow/c/eager/c_api.h
./include/tensorflow/c/eager/c_api_experimental.h
./include/tensorflow/c/eager/dlpack.h
aris@starkiller:~/astro/StarNetv2CLI_linux/tf$

Now, install CUDA and nvidia drivers. At the time of writing, only the version -510 of the nvidia drivers are compatible with the available CUDA packages on Ubuntu 22.04. If you’re using the latest version of the driver (nvidia-driver-515), installing the nvidia-cudnn package will attempt to delete it.

aris@starkiller:~/astro/StarNetv2CLI_linux/tf$ sudo apt-get install nvidia-cudnn nvidia-driver-510

If you were running the nvidia drivers 515 or above and the version of your nvidia drivers changed, you need to reboot before tensorflow will work with your GPU, due to a difference of version between the running and installed drivers.

We now need to link the libtensorflow libraries so they’re found by StarNet++:

aris@starkiller:~/astro/StarNetv2CLI_linux/tf$ ln -sf lib/libtensorflow.so.2 lib/libtensorflow_framework.so.2 .
aris@starkiller:~/astro/StarNetv2CLI_linux/tf$

It’s now time to test and compare the performances of StarNet in GPU mode:

aris@starkiller:~/astro/StarNetv2CLI_linux/tf$ time ./starnet++ ../2022-08-20-M31-v1_LRGB.tif
Reading input image… Done!
Bits per sample: 16
Samples per pixel: 3
Height: 3596
Width: 5328
Restoring neural network checkpoint… Done!
2022-09-02 18:38:31.270863: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-09-02 18:38:31.479773: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-02 18:38:31.480021: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-02 18:38:31.509921: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-02 18:38:31.510177: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-02 18:38:31.510378: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-02 18:38:31.510575: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-02 18:38:32.092283: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-02 18:38:32.092551: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-02 18:38:32.092757: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-02 18:38:32.092963: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-02 18:38:32.093165: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-02 18:38:32.093390: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1532] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 5954 MB memory: -> device: 0, name: NVIDIA GeForce RTX 2080 SUPER, pci bus id: 0000:0a:00.0, compute capability: 7.5
2022-09-02 18:38:32.093804: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:975] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-09-02 18:38:32.094004: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1532] Created device /job:localhost/replica:0/task:0/device:GPU:1 with 6646 MB memory: -> device: 1, name: NVIDIA GeForce RTX 2080 SUPER, pci bus id: 0000:0b:00.0, compute capability: 7.5
Total number of tiles: 315
2022-09-02 18:38:32.184429: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:354] MLIR V1 optimization pass is not enabled
2022-09-02 18:38:34.100134: I tensorflow/stream_executor/cuda/cuda_dnn.cc:384] Loaded cuDNN version 8204
100% finished

Done!

real 0m21,444s
user 0m19,678s
sys 0m1,710s
aris@starkiller:~/astro/StarNetv2CLI_linux$ time ./starnet++ ./2022-08-20-M31-v1_LRGB.tif
Reading input image… Done!
Bits per sample: 16
Samples per pixel: 3
Height: 3596
Width: 5328
Restoring neural network checkpoint… Done!
2022-09-02 18:39:42.337410: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Total number of tiles: 315
100% finished

Done!

real 0m58,745s
user 13m20,388s
sys 2m13,527s

StarNet++ is now running 3 times faster without hogging the CPU for a whole minute.

My journey to astrophotography (part 1)

Astrophotography is an awesome passion that’s a mix of science, technology, history, art and dedication. I’m writing this post to share on my journey, not as a way to teach you anything about astronomy, but to offer a window in my life and also show that it’s possible to get started from zero in a new hobby, provided you invest some time into it.

Three years ago, I wrote a blog post on the reasons why I left my job and was pursuing something better suited to my mindset and where healing some wounds wound be possible. I removed it because a person I’d rather not have read it did (if you think it’s you, please return my calls). One or two years before, I started to notice that not only my job had eaten my hobby, but I was less and less interested in computer security and hacking in general – as doing 2 or 3 hours of hacking at home after having spent the day on a pentest was simply not something I enjoyed anymore. It was time for me to be passionate in something else that didn’t involve reading social media for hours (which is unfortunately one of my other hobbies). Maybe go back to something I always loved without taking the time to explore it, partially because I thought that was out of reach or because I should spend all my time trying to be the best hacker in the world (that didn’t work). A few people may know that I was using the handle “spacewalker” until the mid-2000, it didn’t come out of nowhere but from my fascination for the night sky and poor science-fiction cultural references.

The early days

A first attempt was made in the late 2000, when my dad bought a “telescope” (a toy) to our house in Greece. A well-meaning but misguided decision, because I decided that telescopes suck and we can’t see anything in them. Friendly tip: search “telescope” on amazon and never buy any of the results, DM me instead and we discuss.

Test Panasonic FZ200 : un 600 mm f/2,8 - Les Numériques
Panasonic Lumix FZ-200

A decade later, I bought a decent camera (Panasonic FZ-200) and used it for holiday pictures. I had a long exposure feature that made cool photos, so I tried taking long exposure pictures of the house, the trees and eventually the sky.

Here’s one of the pictures. Terrible technique, terrible processing, but I was amazed that I could see the big dipper on one of my pics.

This picture is one of my first attempts at photographing the Milky Way. Retrospectively it wasn’t that bad if we ignore the weird angle and the light spot that probably caused it.

Around 2017-2018, I was in the mountains in Briançon with family and my camera during the winter, and used some of the evenings to roam around with my camera. I pointed it to the sky and captured this horror:

a few seconds exposure on M42

Getting serious

I started reading a bit on astrophotography on forums and watched tutorials on Youtube (mostly in French). I attempted a few stackings of M42/Orion Nebula but I quickly understood that I’ll never get any good results without a sky tracking equipment. I reduced the choice between the Skywatcher Star Adventurer or one of the entry-level Skywatcher EQ- equatorial mounts. I could fit my camera on it, I already had a decent focal length (around 600mm FF-equivalent due to the very small sensor size). I opted for a motorized EQ5, since I could use it for bigger instruments like a telescope later.

Skywatcher nEQ5 with the Panasonic bridge and a homemade wooden dovetail adapter.

I found one of these mount for a reasonable price on a local second hand website. The seller was very nice and is a member of the astro Club “BW Astronomie.” He encouraged me to subscribe to the Facebook group. I did, introduced myself, went to a few events and astrophotography classes held by people there. I joined as a member, went to meetings and public events. This has been a very important part of my journey: being in a community of amateur astronomers was an invaluable resource for learning new things, share my creations and discuss astronomy. And more importantly, all the friends I made on the way. I thank you all, you may not realize how important it was for me at that time.

If you’re interested in astronomy, astrophotography, would like to observe the sky or buy a telescope, I very strongly recommend you to join a local club. They’re run by passionate people eager to share their passion for the sky. You’ll have the opportunity to try different types of equipment until you find the one that matches your expectations.

APPAREIL PHOTO HYBRIDE SONY PACK ALPHA 6000 + 16-50MM + 55-210MM + SD16GO +  SACOCHE (A6000) | Vanden Borre
Sony A6000 and its kit lenses

That camera sucked for astrophotography. It was old already (~2012), was very noisy and had a non-removable lens, making it impossible to use on any other kind of optics. In may 2018, after an hesitation between Canon and Sony, I opted for a new Sony A6000, with kit lenses 16-50mm and 55-210mm. This camera is good and I still use it today for day photography and occasionally for meteor showers or wide angle photos.

A few weeks later, I bought a wide-angle lens, The Samyang 12mm F/2.0. This is a very fine prime lens.

More seriousness

Samyang 12mm - F2.0 Ncs Cs - Objectif à focale fixe - Convient aux  appareils Sony hybrides | bol.com
Samyang 12mm F/2.0 Sony E

the camera was great but its optics hadn’t enough focal length for the spring night objects (mostly galaxies), so I decided to buy a telescope. I found a used telescope (Skywatcher 150/750), sold with a smaller equatorial mount, a box full of eyepieces for visual observations and a few accessories. It’s the telescope I’m still using today.

Once at home, I installed it and spent most of the night looking at the sky. I observed the planets and saw Saturn for the first time. I ordered a large print of the pic below and it’s hanging on the wall in my office today.

First night observing on the telescope, Sony A6000 @12mm

I finally had a basic tracked telescope + camera setup on which I could take deep sky pictures. Here are a few pictures that I have taken in the beginning of 2019, when I started to have a pretty good understanding of the technique and of the software stacks. More or less at the same time, I resigned from my position in Switzerland and started looking for something closer in Belgium.

Single untracked picture, A6000+Samyang 12mm.
M31 Andromeda galaxy, Sony A6000 and Sony 55-210mm
M101, A6000 and 150/750 Newtonian
One of my first stacked moons.
M51, same setup.

And then?

This is already a quite long blog post, I’ll cover the remaining of the story in a future post. I’ll speak of my equipment, covid life but also of my involvement in BW Astronomie. If you liked this post, you may want to subscribe to my Instagram and see some of my work as soon as I publish it. I may decide in the future to publish some of my pictures on my blog, with a bit of context to understand how the picture was made and what I think of it.

SSH: Best practices

The comments around the last OpenSSH issue (CVE 2016-0777, you must read excellent Qualys’ analysis if you’re interested with the details), I noticed that many people were not aware of some basic features of OpenSSH. I will attempt to give a few advises, prioritized in feasibility order, and with graphical annotations:

Very easy to set up.

Requires a lot of work to set up.

Will provide you some protections against difficult attacks.

Will protect against very simple or effective attacks.

Continue reading “SSH: Best practices”

TrendMicro CTF 2015 : Poison Ivy (Defense 300) write-up

TrendMicro CTF logo

The challenge

This challenge was one of the 25 (minus a few canceled ones) written and organized by TrendMicro for their TMCTF 2015. I played with the Swiss team “On est pas contents” and I won’t disclose how badly we ranked 🙂 Some challenges were really boring (a crossword where half the solutions come from the commercial product aisle? Not for me). Some were frustrating, and one was really great: Poison Ivy network capture.

TrendMicro was very fast in shutting down the whole CTF website, so I can’t get an hand on the original challenge text. From memory:

A hacker was caught using Poison Ivy on a real system. Please understand what he was doing to get the flag. (ps: password is admin).

With that exciting information I start downloading the pcap. Opening in wireshark, it appears it’s a single TCP connection on the 443 port. This doesn’t look like https and the wireshark dissector doesn’t want to parse it. Right click on a packet, “Decode as…” and check “do not decode” makes us see the raw exchange.

tmctf_wireshark1

Continue reading “TrendMicro CTF 2015 : Poison Ivy (Defense 300) write-up”