Tag: ai

  • Converting docker containers into AppImages

    In Linux, packages are the conventional way to distribute software. These packages are usually made of executable files, scripts and various other files. Examples include RPMs and Deb archives. While very useful, these packaging formats have a downside: they are distribution specific. Even if two distributions use the same packaging format, for instance Ubuntu and Debian, they are not compatible. Even further, packages may not be compatible between two different releases of the same Linux distribution, for instance Debian stable and Debian unstable. Consequently software, on Linux, needs to be built for every combinations of Linux distribution / releases out there.

    For simple open source software, like terminal applications, this isn’t usually a big issue, as volunteers can usually take the code and release it for the distribution of their choice making small adjustments to the code (at least in principle). For more complicated software and proprietary software this is trickier. However there is a solution to this problem: open source developers have created various universal packaging formats. The main ones are Flatpak, Snaps and AppImage. But there are many others, technically Docker is also a mean to distributed software. One can count also Steam distributables, if you think about it. And even Nix packages are in some way distribution agnostic as you can install Nix on many Linux distributions.

    I personally think AppImage lacks a little bit of love. It does not offer as many features as Flatpak or Snaps, which handle sand-boxing, software distribution, and sharing frameworks, but it is very simple and easy to grasp. AppImages are already fairly popular amongst QT applications, electron applications, and even some games like OpenRA. However there are few tools to create AppImages. So I decided to create another tool, which creates AppImages from Docker containers. Furthermore, there is plenty documentation on creating Docker images and the collection of publicly available Docker images is very large. The tool’s name docker2appimage available on Github at https://github.com/mparusinski/docker2appimage.

    Using docker2appimage

    If you have a container called relaxed_beaver, to create an AppImage from this containers, triggering default command, you run.

    docker2appimage relaxed_beaver

    You can perform more complex tasks like request docker2appimage to create an AppImage named alpine-ls from the alpine Docker image that calls ls

    docker2appimage -x ls --name alpine-ls -i alpine

    In order to work the tool requires the appimagetool AppImage as well imagemagick to be installed on the system. The entire tool, in order to be portable, is a simple shell script.

    Here is an even more complex example where we create an universal binary for ripgrep a popular alternative for grep:

    docker run -dit --name=ripgrep ubuntu bash
    docker exec -i ripgrep bash <<'EOF'
      apt-get update
      apt-get install -y ripgrep
    EOF
    docker2appimage -x rg ripgrep

    Most Docker images are server side software (e.g. nginx), OS containers (e.g. alpine) and programming frameworks. Naturally docker2appimage will fit well to create CLI-only AppImage although it is possible to create GUI based AppImages as well.

    Shortcomings and next steps

    There are some limitations of course. Many Docker images default commands are shells like bash, sh, … one might even include Python as a type of shell. AppImage works by using environment variables and Fuse to create a pseudo virtual environment; this virtual environment is then used to launched commands. As a result, handling shell commands is tricky and right now is not supported.

    The project is still ongoing development to support many applications and Linux distributions. If you have some time and are curious do not hesitate to test the tool and report any bugs you see.

  • Pixel Pal (PART 6) : Early progress reports

    This article is part of a series about upscaling icon themes with AI. While this page is part 6, part 5 is available here.

    Pixel Pal is a project I have started to bring new life to old icon themes. Many old icon themes are in raster format and are not suited to HiDPI screens. Currently, the only way to handle old icon themes is to turn one pixel into four or nine, but the result looks pixelated. The goal of this project is to use deep learning to upsample small icons into icons for HiDPI screens..

    There is some progress as this example shows.

    Source 32 by 32 pixel versionTarget 64 by 64 pixel (ideal) versionNeural network augmented output
    Original 32 by 32 pixel icon showing a non empty folder which served as input to the neural network.Original 64 by 64 pixel icon showing a non empty folder which served as target to the neural network.Upscaled 64 by 364 pixel icon showing a non empty folder which can produced by the neural network.

    More examples can be found in the below PDF

  • Pixel Pal (PART 5) : Data augmentation

    This article is part of a series about upscaling icon themes with AI. While this page is part 4, part 3 is available here and part 5 is available here.

    Pixel Pal is a project I have started to bring new life to old icon themes. Many old icon themes are in raster format and are not suited to HiDPI screens. Currently, the only way to handle old icon themes is to turn one pixel into four or nine, but the result looks pixelated. The goal of this project is to use deep learning to upsample small icons into icons for HiDPI screens.

    One of the big challenges in deep learning is getting enough data. Neural networks can easily have millions of parameters, and fine-tuning them requires a large quantity of data. Getting enough data is a challenge, but what makes it worse is that data alone is not enough: you need labelled data and, if possible, high-quality labelled data.

    When you don’t have enough data, you have a problem. There are many ways to tackle this issue:

    1. Reducing the number of parameters to learn. One way is to reuse the weights (parameters) from a model already trained on another task, and then retrain only parts of it. This is a form of transfer learning. For instance, VGG-16 is trained for general-purpose image classification. You can take this model and retrain only parts of it, assuming it generalise well.
    2. Training parts of the model on the input data alone using autoencoders. This is fairly technical. It is a model which compresses the input and then decompresses it with as little loss of quality as possible. Such a model is easier to train, because you usually have lots of input data (but not necessarily output data). Then you take the trained autoencoder and split it in two: the compression network and the decompression network. You can then work with the compressed features coming out of the compression network in place of the original input data. The benefit is that the compressed features are smaller. As a result, the network you need to train to map the compressed features to the output data is also smaller, and therefore simpler to train.
    3. Using data augmentation. This consists of building new data from the existing data, and it is especially good at producing neural networks that generalise well. Through data augmentation, you can tell a neural network what it should not rely on. For instance, one way to augment image data is to flip the image horizontally and vertically; this way, you can easily quadruple the amount of data available and tell the network it should not rely on the image being a certain way, like having shadows at the bottom.

    For this project, I will rely on data augmentation. My training data set is around 9,000 images, which is fairly good for networks with tens of thousands of parameters. But through data augmentation, my neural network can do even better: by simply flipping horizontally and vertically, I can easily get around 36,000 images, which allows me to investigate deeper neural networks.

    ModificationNo horizontal flipHorizontal flip
    No vertical flipOriginal image of a black and white wifi icon with no modification appliedOriginal image of a black and white wifi icon flipped horizontally
    Vertical flipOriginal image of a black and white wifi icon flipped verticallyOriginal image of a black and white wifi icon flipped horizontally and vertically

  • Pixel Pal (PART 4) : Training a model

    This article is part of a series about upscaling icon themes with AI. While this page is part 4, part 3 is available here and part 5 is available here.

    Pixel Pal is a project I have started whose purpose is to bring new life to old icon themes. Many old icon themes are in raster format and are not available for HiDPI screens (their resolution are too small). Currently the only way to handle old icon themes is to turn one pixels into four or nine. But it looks pixelated. The goal of this project is to use deep learning to upsample small icons into icons for HiDPI screens.

    In this part I will be training models. To build and train models I will use _Tensorflow: https://www.tensorflow.org/ and _Keras: https://keras.io/. Tensorflow and keras are at this point the industry standard for neural networks in Python. I won’t explain how to train networks in Keras. This is already widely covered. In this section I want to talk about a couple of important things to do when training to avoid wasting time (training well is time consuming):

    1. Output metrics during learning not just the loss to visualise the learning live.
    2. Use a validation dataset to measure the progress of learning on a dataset which is different from the training dataset. The point is to see the real progress of the learning and spot early issues like overfitting (or learning too fast).
    3. Use a early stopping callback : This will check the progress of the validation metrics and stop the learning if the training algorithm is no longer learning. This helps avoid of leaving the training algorithm going on for nothing.
    4. Use checkpoints : This will save the model regularly and if your training crashes you can restart from where you left.
    5. Regularly save the output (as an image) of the neural network on fixed image inputs. This helps you visualise the progress of the learning.
  • Pixel Pal (PART 3) : Measuring model quality

    This article is part of a series about upscaling icon themes with AI. While this page is part 3, part 2 is available here and part 4 is available here.

    Pixel Pal is a project I have started whose purpose is to bring new life to old icon themes. Many old icon themes are in raster format and are not available for HiDPI screens. Because the icons are low-resolution. Currently the only way to handle old icon themes is to resample them by the desired factor, but the icons look pixelated. The goal of this project is to upscale icon themes with AI.

    In this part I will cover losses, metrics and targets. Before going on about training deep learning networks to upsample intelligently icon images, we need ways to measure whether our models are doing a good job. In particular, I need to know if a model does better than simply pixel doubling.

    Low resolution 64 pixels by 64 pixels icon of a non empty folder
    Low resolution 32 pixels by 32 pixels icon of a non empty folder

    The images above show side by side the same vector icon but the left icon was rasterised as a 32 by 32 pixel image and the right icon was rasterized as a 64 by 64 pixel image. Furthermore, the former was upsampled using pixel doubling.

    As you can see the two images are similar but not identical. I need some way to measure how similar the two are. Simply counting the number of identical pixels is problematic. Just because two pixels aren’t identical does not mean they are not similar. Counting the number of identical pixels as a metric will probably be too strict. So, for this project, I will rely on two metrics suggested in the following article: An Introduction to Super Resolution using Deep Learning. The metrics in question are the following:

    1. Peak Signal-to-Noise Ratio (PSNR)
    2. Structural Similarity (SSIM)

    For reference the metrics for the pair of images above are :

    1. Peak Signal-to-Noise Ratio: 16.91 dB
    2. Structural Similarity: 0.83

    Measuring how similar two images are is already a good start. It provides us an idea of how well our models are working. However, there are some limits to metrics:

    • Metrics are not always differentiable. However training neural networks requires a way to measure the distance between the desired output and the output the network is producing. This is where losses come into play.
    • You need to have some good baselines. In other words, the metric in itself is not useful; you need to have an objective. Such as doing better than simple pixel doubling or bicubic interpolation.
    • Metrics will be sensitive to the data you use. You may end up with images that are easy to upsample, and the metric may be deceptively good. This is why you should compute the metrics on the entire dataset and do some statistics on it.
    • Metrics are not perfect. In the end we want something to be visually pleasing not something that maximises a mathematical function. This is why you should also visually inspect the output of a neural networks.

    To train the network, I will use a loss function. Loss function are ways to measure the distance between the ideal output and the current output. In our case, I will use mean squared error as it is simple and fits our purpose. Always make sure you are using an appropriate loss function.

    My objective will be to perform better than straight upsampling via nearest-neighbour and bilinear interpolation.

  • Pixel Pal (PART 2) : Gathering data for Pixel Pal

    This article is part of a series about upscaling icon themes with AI. While this page is part 2, part 1 is available here and part 3 is available here.

    Pixel Pal is a project I have started whose purpose is to bring new life to old icon themes. Many old icon themes are in raster format and are not available for HiDPI screens. Because the icons are low-resolution. Currently the only way to handle old icon themes is to resample them by the desired factor, but the icons look pixelated. The goal of this project is to upscale icon themes with AI.

    To solve this, I will use artificial intelligence and more precisely, deep learning. The idea is to train a neural network how to upsample icons in a manner that takes into account the shape of the underlying icon. In other words the idea is to do better than increasing the number of pixels. However, to train a neural network you need lots of data. In our case the data is a collection of icons for which we have both low resolution and HiDPI resolution versions.

    Thankfully, a lot of icon themes are available for which we have both. There are some requirements:

    1. The icon theme’s license needs to allow make derivatives. To be safe, I will stick to open source licenses.
    2. There needs to be enough data to train a network. However, I will intentionally not get too much data to explore data augmentation techniques.
    3. We need to have the ability to split data well in various sets: training, validation, test and real world data

    Let me explain the splitting of the data a little more by using an analogy. Training a network is a bit like taking a course at university. You get a lot of material through the course and at the end of the course there is a final exam. You are not allowed to see the final exam.

    The course material is your real training data, and the final exam is test data. The point of test data is to evaluate the real performance of the network. But the test data is not part of the course. For the test data I have another real-world dataset which is there for me to use the network a first time on a real task; in other words, non-course material. The real world data will correspond to some old icon themes (OS/2, CDE).

    Furthermore, real training data will be split. To use our analogy to learn the course and pass the final exam with a good grade you do practice tests. This is done by splitting our real training data into a smaller training data set and a validation data set.

    So, to recap, we have :

    1. Training data : Use for training the network
    2. Validation data : Use for evaluating the training
    3. Test data : Use for evaluating the performance of the network
    4. Real world data : To test the use of the software on an actual use case.

    Let me explain a bit more about the use of real world data. I have chosen two very old icon themes for which no SVG formats are available. This data set allows me to judge whether the project has been a success qualitatively.

    Because no SVG files are available an official metric can’t be calculated, which is why we need test data with SVG icons. Using old icons with no SVG file format will show whether using deep learning is actually useful for reviving old icon themes. The old icon themes are the official CDE icon theme and the icon theme from OS/2.