Run Keras with CentOS7 + Anaconda + Django + Apache

I wanted to run an image processing program made with Anaconda with Apache + Django, so a simple memo for myself. I don't do anything like SSL or security. It is a continuation of https://qiita.com/hinoma/items/5b881b8ac531a0ba7953. For the time being, it is the main character. I haven't prepared the images yet, so I'll post them when I can.

Django project

CSS does not work if the previous article is as it is. Therefore, edit setting.py.

setting.py


import os
TEMOLATES = [
  {
     'DIRS' : [os.path.join(BASE_DIR, 'templates')]


LANGUAGE_CODE = 'ja'
TIME_ZONE = 'Asia/Tokyo'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

After that, create a static directory and templates directory in the same hierarchy as manage.py. Put the css file in the static directory and the html file in the templates directory.

/etc/httpd/conf.d/django.conf


#Postscript
WSGIApplicationGroup %{GLOBAL}
WSGIPythonHome /usr/local/bin/pyenv/versions/anaconda3-4.4.0/

Alias /static/ /var/www/komon/static/
<Directory /var/www/komon/staitc>
  Require all granted
</Directory>
# python manage.py collectstatic

Let's do this.

Run a machine learning program

Since you may use opencv, keras, tensorflow, etc., install these.

# pip install opencv-python==4.4.0.44
# conda install keras=2.2.4
# conda install numpy=1.16.2
# conda install tensorflow=1.13.1

If you install keras = 2.2.4, numpy1.18 will be installed, but downgrade is required because it is incompatible with this.

libstdc++.so.6 version cxxabi_1.3.8' not found This is the error that occurred when I ran apache. Apparently, there is no cxxabi_1.3.8 in libstdc ++. So.6

# strings /usr/lib64/libstdc++.so.6 | grep CXXABI_
CXXABI_1.3
CXXABI_1.3.1
CXXABI_1.3.2
CXXABI_1.3.3
CXXABI_1.3.4
CXXABI_1.3.5
CXXABI_1.3.6
CXXABI_1.3.7

Apparently there is no 1.3.8, so I need to get this somehow.

# cp /usr/local/bin/pyenv/versions/anaconda3-4.4.0/lib/libstdc++.so.6.0.26 /usr/lib64/
# mv libstdc++.so.6 libstdc++.so.6.bak
# ln -s libstdc++.so.6.0.26 libstdc++.so.6
# string /usr/lib64/libstdc++.so.6 | grep CXXABI_
(CXXABI_1.3.8 is all you need)
# systemctl restart httpd

If you're happy with this, go to views.py in your django project.


import tensorflow as tf

I think it's okay if the screen is displayed by hitting the IP from an external PC after adding such as.

When you want to display "Japanese" on an image for image recognition etc.

If it is alphanumeric

cv2.putText(Image path,Characters you want to display, (x, y), cv2.FONT_HERSHEY_PLAIN, 2,color, 1, cv2.LINE_AA)

It can be displayed with etc., but Japanese cannot be displayed with opencv, so use pillow

from PIL import Image, ImageFont, ImageDraw

Passes through the program, but since it is necessary to read the font when displaying Japanese, read it with the following code.

font = ImageFont.truetype(fontpath, fontsize)

This can cause errors in some cases

The _imagingft C module is not installed

When becomes, the solution should be as follows.

# yum install freetype-devel libjpeg-devel libpng-devel
# pip uninstall pil pillow
# pip install pillow
# pip list
(Check if there is a pillow with this)

It worked in my environment.

Recommended Posts

Run Keras with CentOS7 + Anaconda + Django + Apache
CentOS8 + Anaconda + Django development environment construction procedure
Run old Vivado with Docker guest OS as CentOS 7.4
Use CentOS with LXD
Run Payara with Docker
Build Growai with Centos7
[Vagrant] Prepare LAMP development environment with Vagrant (centos + apache + MySQL + PHP)