Rest API for TensorFlow model

TensorFlow Serving, sources - library for serving machine learning models. Written in C++ and Python. Server is in C++. Requires Bazel - Google’s build tool. Doesn’t work with python 3. Probably fast. TensorFlow: How to freeze a model and serve it with a python API Building a Machine Learning App with AWS Lambda (slides) Pipeline.io - End-to-End, Continuous Spark ML + Tensorflow AI Data Pipelines, Sources Interesting thread. They propose to use “saved_model_cli binary (in tools/), which you can feed a SavedModel, and pass input data via files....

May 21, 2017 · SergeM

Mocking in Python

Let’s consider how python standard unittest module suppose to use mocks. Assume we want to test a method that creates and uses objects of other classes: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 # content of module.py # classes that we want to mock class ClassName1: pass class ClassName2: pass # class that we want to test class ProductionClass: def foo(self, parameter1, parameter2): object1 = module....

March 6, 2017 · SergeM

Correct way of running long tasks in Flask

Key to the answer is Celery. Good post: Using Celery With Flask Sources See also: Making an asynchronous task in Flask Sharing memory and using multiprocessing along with gunicorn seem to be wrong solutions.

January 23, 2017 · SergeM

Image processing in Python

Image search using elastic search Comparison of Image Search Performance using different kinds of vectors Plugin for elastic search Personalizing image search with feature vectors and Lucene (video) Operations on images in python How to set thresholds for Canny edge detector in openCV Zero-parameter, automatic Canny edge detection with Python and OpenCV 1 2 3 4 5 6 7 8 9 10 11 def auto_canny(image, sigma=0.33): # compute the median of the single channel pixel intensities v = np....

January 15, 2017 · SergeM

Run docker as pytest fixture

I need to test external API or perform integration test for my application. The extenal application can be accessible through docker image. I want to write a test that has docker run as set-up step docker stop/docker rm as tear down step As an example lets consider Seaweedfs as external API. SeaweedFS is a simple and highly scalable distributed file system. To run it you need to run master and slave images....

December 19, 2016 · SergeM

Testing json responses in Flask REST apps with pytest

Testing is an essential part of software developmnet process. Unfortunately best prictives for python are established not as good as for example in Java world. Here I try to explain how to test Flask-based web applications. We want to test endpoints behaviour including status codes and parameters encoding. It means testing of handler functions for those endpoints is not enough. Tests for endpoints can be considered/used as high-level acceptance tests....

November 27, 2016 · SergeM

Refactoring python code. Extracting variables and other.

Pycon2016 talk by Brett Slatkin Example 1: Extract variable import random month = random.choice(MONTHS) if (month.lower().endswith('r') or month.lower().endswith('ary')): print('%s is a good time to eat oysters' % month) elif 8 > MONTHS.index(month) > 4: print('%s is a good time to eat tomatoes' % month) else: print('%s is a good time to eat asparagus' % month) Becomes: class OystersGood: def __init__(self, month): month = month month_lowered = month.lower() self.ends_in_r = month_lowered.endswith('r') self....

October 8, 2016 · SergeM

Useful python links

Books Test-Driven Development with Python Harry Percival Python Testing with unittest, nose, pytest : eBook Testing Python: Applying Unit Testing, TDD, BDD and Acceptance Testing link . Videos Outside-In TDD Harry Percival, PyCon 2016 Докеризация веб приложения на Python, Антон Егоров Thinking about Concurrency, Raymond Hettinger, Python core developer Tutorials Разработка идеального pypi пакета с поддержкой разных версий python (Rus), 2020. The Little Book of Python Anti-Patterns - an awesome collection of best practices with examples....

October 8, 2016 · SergeM

pypy with numpy

Looks like pypy now can build numpy. Well, a slightly modified numpy. Get default branch of pypy. be careful cause the developers don’t maintain default branch compilable. Revision 84341 (c86b42dd7613) works for me. compile using ./rpython/bin/rpython -O2 ./pypy/goal/targetpypystandalone.py --withoutmod-micronumpy Create package and vitual environment. Something like this: ./pypy/tool/release/package.py --targetdir ./my_builds/build.tar.bz2 --builddir ./tmp/ --nostrip --archive-name pypy_84341 Needed to copy pypy-c and libpypy to pypy/goal beforehand. Clone and follow instructions from https://github.com/pypy/numpy/commits/cpyext-ext Revision 3299d0d76fdb831fbcb4429a89c1f53bb36ea07f worked for me...

May 16, 2016 · SergeM

About python

Production Database helpers for sqlalchemy Backend-agnostic database creation (CREATE IF NOT EXISTS): 1 2 if not database_exists('postgres://postgres@localhost/name'): create_database('postgres://postgres@localhost/name') Possible with SQLAlchemy-Utils library. See docs Infrastructure with Python http://dustinrcollins.com/infrastructure-with-python – list of tools for python development Retry libraries for python tenacity - a fork of retrying. Seems alive and powerful. retrying - abandoned but popular project. backoff Language Cheat Sheet: Writing Python 2-3 compatible code http://python-future.org/compatible_idioms.html Google Python Guidelines https://google.github.io/styleguide/pyguide.html Inheritance https://rhettinger....

May 1, 2016 · SergeM