During my first encounter of handling JSON (de)serialization in Python, I faced the problem of (de)serializing objects that have properties that are instances of another class. Using the json module, one has to write two methods, a complex_handler and a class_mapper that are fed to json.dumps and json.loads respectively. The design problem here is that the class_mapper needs to compare a dict that is to be deserialized with the properties of potential classes in order to find the matching type. In the first level of deserialization one could potentially provide the type as a parameter to the deserialization-function, but as soon as there is a child property, the type may be unknown. Therefore each class that is to be deserialized has to be registered into a collection of (properties) -> class mappings. To simplify the handling, I wrote the following JsonConvert class: Now we can define some classes and make…
Tag: python
Running Tensorflow with native Linux Binaries in the Windows Subsystem for Linux
After 4 hours of unsuccessful attempts to set up tensorflow in Docker on Windows, I decided to – just for fun – try to run it in the shiny new Windows Subsystem for Linux on my Windows 10 Insider Preview Build 14332. What began with low expectations turned out to be very successful, so here are the steps: First enable the Windows Subsystem for Linux in the “Turn Windows features on or off” dialog: Then open the Ubuntu Bash and update the package index: You can now proceed to install pip for Python 2: Now install the CPU-enabled Linux x64 tensorflow package:: Tensorflow is now installed. With the following command, you can get the directory of the installed package: This should give something like “/usr/local/lib/python2.7/dist-packages/tensorflow”. Now let’s cd to the directory with the example implementation of a CNN for the MNIST dataset: And run the convolutional neural network: In the…
printprev() – print Python sourcecode to console
Print your Python source code to the console. For structure, monitoring or whatever purpose you can think of.