How to turn circles into squares?

Hi, I’m familiar with coding, but I’m new to AI and ML in general. I don’t expect instructions on how to do it. But to know what I should learn, so I can seek a course or an article.

I know I can train the AI to identify circles and squares. But what do I need to know, to be able to transform images of circles into squares?

The final product is an AI that I can select an image of a circle, and it will create a copy of the image, with a square of the same color and size instead of a circle. And save the image to a folder.

What kind of knowledge do I need to do it? Is it possible using the Perceptilabs software? What do I need besides the software?

Thank you in advance.

Hi @avani

That is a very nice question! Simple enough to communicate clearly, yet it entails a number of interesting things and provides an opportunity for AI/ML thinking…

Here’s an experiment you could try in PL - i.e. yes, I think you can do this and learn a lot from it in PL!

  • Create a number of image pairs - one image containing a circle - in a random location, with random size, colour etc. and anothe containing a square centered in the same place as the circle, with the same colour and size… side of square = diameter of circle? (you can program image generation any way you like… but developing your python skills wouldn’t hurt since most ML is done in python)
  • Create as many as you can, but at least 1,000, and maybe, use a power of 2, i.e. 1024, 4096, 65536… as batch sizes are usually in powers of two
  • Don’t make the images too big 256x256 would be more than enough to begin with I think
  • Create a CSV file that specifies the circle images as input and the square images as target, then create a PL model from this

Now, what goes between the input and the target you can vary later (once PL has created a basic model for you), by looking at examples here and elsewhere, bearing in mind that the most basic idea of ML we can apply here is that training in this case comprises (very, very loosely!) comparing the input to the to the target (the “forward pass”) and passing back through the layers between the target and the input adjustments to the weights and biases that will progressively reduce the error (“back propagation”).

Once your network has been trained, in principle it would take a circle as input and “predict” the corresponding square from it.

Now, using your model to make new “predictions” currently requires some additional work but @robertl has provided some example scripts, and @birdstream has already done this for one of his models so there are people who can help with that too.

Beyond this most basic example, you could consider what happens if the circle is not entirely in the image, what orientation should the squares have - could you make it depend on colour, for example? :slight_smile:

You will need only a python installation - but if your PC has nVidia graphics and you can use CUDA that will speed things up.

Don’t hesitate to share your progress or ask for more input!

Good luck :slight_smile:

1 Like

Thank you so much. I’ll use it to learn and get started on ML

I’m trying to follow this tutorial that is currently deprecated. I see I don’t have the same things he is using, like the Data tab next to Processing and the Switch under Operations.

Is it in a different place in the current version? I couldn’t find it.
Or is my version (Free) limited, and don’t offer these options?

Hi @avani

Yes, the “deprecated” label reflects the fact that the tutorial is using V0.11.x of PerceptiLabs which is now at V0.12.25.

Among the differences, GANs have been temporarily removed so that other core capabilities could receive stronger focus without too many dependencies to manage, but as far as I know, you can still install V0.11.15 for example and use that version. For that you need to specify the version explicitly to the pip install command - let us know if you need help with that (TBH, I know how to install a specific version from scratch, but not how to downgrade an existing setup)

On the other hand, @robertl might be able to suggest a good approach using the latest version… either way I hope you’ll be making progress again soon!

1 Like

TBH, I know how to install a specific version from scratch, but not how to downgrade an existing setup

Downgrading from an existing setup is the same as upgrading in pip, so you would just need to run pip install --upgrad perceptilabs==0.11.15, although I would recommend just creating a new environment instead :slight_smile:

As an alternative method, you can try a simple image-to-image translation and see how well that works, that should be able to convert your circle images into squares, although it falls a bit short compared to GAN.
How well did it ran if you just try with the recommended model?