Neural networks and cloud IDE: setup and run Tensorflow on Codenvy
by Svitla Team
This post describes how to setup the Tensorflow library on a cloud integrated development environment Codenvy and run a simple example based on neural network. All software and cloud systems described in this neural networks training are available free. Also, Codenvy allows subscribing to their paid services to extend required system parameters.
Why Cloud IDE
Cloud IDE (Integrated Development Environment) is a good solution for homebrew projects or even for commercial software development. It unifies all workflows with source codes for the project and provides good performance for building, deploying, and testing procedures. Most of the cloud IDEs are accessible from a browser that means anyone can open a workplace and continue working on a project in a few clicks.
Codenvy is a cloud IDE and developer workspace server that allows anyone to contribute to a project without having to install software. The advantages of Codenvy:
- It allows starting your project free.
- A user interface for an integrated development environment is very well organized and suits for any browser.
- It offers a variety of environments and frameworks, including Python, PHP, C++, Java and many others.
- In Codenvy, you have access to terminal command interface and connection to external internet resources. Even sudo command is available in your command line that allows installing many custom libraries or tools if necessary.
Please take into consideration that Codenvy IDE can be slow on free account for large computation task, but it is quite enough for education and research purposes.
Why Tensorflow for neural networks
There are numerous open-source frameworks for machine learning and artificial neural networks.
One of them is Tensorflow. Tensorflow is a free library from Google for computing operations on tensors which is very popular for building neural networks and machine learning. This framework works with Python and GPU boards to operate with large computational tasks.
Tensorflow allows working with numerical computations based on graphs. Every graph flow represents a tensor (multidimensional array), and this helps represent a complex computational sequence of mathematical operation. It perfectly works with neural networks code, because tensors represent layers of artificial neurons.
For deeper learning, read this article.
Working with git and continuous integration
Codenvy IDE offers great built-in integration with git. If you prefer using a command-line git, it also works in Codenvy terminal ‘from the box.’
You can configure a continuous integration tool and deploy all sources to your production servers, such as Amazon, Azure or Google. If you need a powerful computation environment, you can deploy it on a cloud instance with GPU (for example, it is available from Amazon EC2 P2 with 16 NVIDIA Tesla GPU board).
How to setup Tensorflow in Codenvy
1. Go to codenvy.io and register for free or login with your existing Google account.
2. Create a Python workplace with python3 and pip.
3. Create a Python project in codenvy.io. Click on ‘Workplace’ -> ‘Create Project’ -> select ‘Python’ and enter a name.
4. Go to a Terminal window in your workplace by clicking menu ‘Run’ -> ‘Terminal.’
5. To install Tensorflow by pip3 type the following command in terminal:
sudo pip3 install tensorflow
6. In file main.py:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
7. To start your example in Tensorflow from terminal:
This command will generate console output like b'Hello, TensorFlow!'
8. After your work is done, select in menu ‘Workplace’ -> ‘Stop.’
You can set 3Gb of memory for this workplace and connect your github to it.
Your first Tensorflow neural network in cloud IDE
Now you have Tensorflow installed on your cloud IDE.
Let’s run some classical neural networks, for instance, XOR logical function. You can easily find Python code for Tensorflow. A good example is available here.
In your Codenvy environment, click ‘Workplace’ -> ‘Create Project’ on the top menu. Then select Python in the left part of a dialog box enter XOR in field ‘Name:’ and click ‘Create’ button. Select ‘Project’ tab on the left of the main window and open a project ‘XOR.’
Click on main.py to open in the editor. Then, copy Python code from mentioned GitHub and paste it to this file. Finally, open a terminal window from Codenvy top menu ‘Run’ -> ‘Terminal’ and enter the following command:
You will see some text output from a neural network training process and file xor_logs created in your directory ./logs/
Congratulations! Your first neural network example works in Codenvy cloud IDE.
How to run Tensorboard on codenvy.io
Tensorboard is a great visualization tool for Tensorflow graph of computations. It allows displaying a data flow step by step. It helps understand a sequence of operations in Tensorflow code. Every time running Tensorflow computation, you can create a special log file with log information. This code is loaded to Tensorboard and shows a graph of computation in a web browser. This line in Python code will write log file xor_logs in folder logs:
To run a tensorboard tool in Codenvy and display an image of the computation graph in your browser, do the following.
1. Go to your dashboard, find your workplace, and click on a ‘Configure workplace’ icon (gear).
2. Go to Server section and select an ‘Add Server’ button.
3. Enter Reference: tensorflow, Port: 6006, protocol: http and click "Add". Be aware, this http connection will be insecure, so do not enter any sensitive data or use https connection.
4. Run your workplace on Codenvy.
5. Copy an address from the Server section.
6. Run the command in the terminal window on your workplace. Let’s assume you run a tensorflow with some neural networks and have a log file in ./logs/xor_log
7. Open a new tab in your browser and go to the address http://node20.codenvy.io:53274/ (note: the address will be different on your specific environment).
Endnotes on neural networks modeling
Such an interesting combination as Tensorflow and Codenvy is efficient for training purposes or supporting different environments simultaneously, and you cannot use your computer directly for these purposes. Of course, Tensorflow in such a setup cannot be fast as on the video board GPU, but it is still very good for the start. For the production version, you can use another cloud system where you can deploy your project and continue developing in Codenvy IDE.
As the neural networks and learning machines development community expands and the industry evolves, we look forward to see even more mature frameworks and tools. Follow our blog not to miss anything interesting on the topic.
Let's meet Svitla
We look forward to sharing our expertise, consulting you about your product idea, or helping you find the right solution for an existing project.
Your message is received. Svitla's sales manager of your region will contact you to discuss how we could be helpful.