發表文章

[Debug] Code 502: Error as sending POST requests iteratively to OCR API deployed on Google App Engine

OCR Service Brief: POST a file -> OCR service interfaces API (on APP Engine) : encoded file as base64 string -> OCR backend engine Issue Description: An OCR service (Flask REST API) deployed on GAE (Google App Engine) cannot respond correctly when users use iteratively send POST requests. Sample code is shown below: for i, path in enumerate(path_list):     file_path = str(path)     perform_ocr(file_path)     #sleep(5) Debugging: Calling the service file by file separately doesn't occur errors. Service works well on the local laptop but has issues after being deployed on Google App Engine. Using sleep() function which can alleviate the issue but does not entirely solve it. The service would be stuck sometimes. After tracing the code, the error occurred as the OCR API server does not actually receive the POST file content but it does get the file name of the file. Therefore, OCR backend engine doesn't get the to-be-processed file and ...

How to write equation in Blogger?

1. Go to "Theme" and select one of the "Contempo" themes. 2. Click "Edit HTML" and paste below script under <head> tag.     <script type='text/x-mathjax-config'>     //<![CDATA[       MathJax.Hub.Config({         tex2jax: {           inlineMath: [ ['\$','\$'], ["\\(","\\)"] ],           displayMath: [ ['$$','$$'], ["\\[","\\]"] ],           processEscapes: true         },         "HTML-CSS": { availableFonts: ["TeX"] }       });     //]]>     </script> 3. Save theme. 4. Use $...$ to bracket the equation. E.g., $E=mc^2$ =>  $E=mc^2$ Ref:  https://support.google.com/blogger/forum/AAAAY7oIW-wcC761lmV8jA?authuser=0&msgid=CHFoXAQQAwAJ

whereis python

/usr/bin/

Python: Using pydot and Graphviz to generate PDF file for Decision Tree

from sklearn import datasets from sklearn import tree from sklearn .externals.six import StringIO import pydot clf = tree.DecisionTreeClassifier() clf = clf.fit(iris.data, iris.target) dot_data = StringIO() tree.export_graphviz(clf, out_file=dot_data) graph = pydot.graph_from_dot_data(dot_data.getvalue()) graph.write_pdf("iris.pdf") Remark: (OS: OS X El Capitan) 1. You must install pydot2 firstly. pip install pydot2 2. Then, you must install Graphviz by using "brew" brew install graphviz 3. How to install Homebrew ruby -e " $( curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install ) " Ref: http://stackoverflow.com/questions/18438997/why-is-pydot-unable-to-find-graphvizs-executables-in-windows-8 http://stackoverflow.com/questions/27666846/pydot-invocationexception-graphvizs-executables-not-found http://hackercodex.com/guide/python-development-environment-on-mac-osx/ http://hackercodex.com/guide/mac-osx-maveri...

Python: List Comprehensions

If I'd like to create a list based on the existing objects (maybe a list or a sequence of numbers), it's a good way to achieve the goal. I often use this to build a list of files. For example, output = [open('output_%s' %(i), 'w+') for i in range(6, 10, 1)] The program will generate four files named output_6, output_7, output_8, and output_9. Reference: http://www.swaroopch.com/notes/python/#list_comprehension