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 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

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

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 Put the css file in the static directory and the html file in the templates directory.


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
# python collectstatic

Let's do this.

Run a machine learning program

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

# pip install opencv-python==
# 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. 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/ | grep CXXABI_

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/ /usr/lib64/
# mv
# ln -s
# string /usr/lib64/ | grep CXXABI_
(CXXABI_1.3.8 is all you need)
# systemctl restart httpd

If you're happy with this, go to 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)