1

Hello I'm trying to build a simple api to receive an image and return some inference values. My filesystem is the following:

Mask_RCNN
   |-MaskDetector.py
        |-FireDetector(class)
fire_app
   |-server.py
   |-saved_img

If I open python console and run this:

import sys
sys.path.insert(0, '../Mask_RCNN')
new FireDetector.FireDetector('../trained_weights')
fire_detector.detect('/home/fctmasterthesis/fire_app/saved_img/image7.jpg')

It returns the expected result of inference:

({'rois': array([[ 238,  170,  988, 1359], (...)

But if I run it inside Flask server.py like this:

 from flask import Flask
from flask import render_template
from flask import request, flash, redirect
from werkzeug.utils import secure_filename
import os
import sys
sys.path.insert(0, '../Mask_RCNN')

from MaskDetector import FireDetector
fire_detector = FireDetector('../trained_weights')

UPLOAD_FOLDER = 'saved_img'
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg'])

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
    return '.' in filename and \
            filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS

@app.route('/',methods=['GET', 'POST'])
def hello():
    if request.method == 'POST':
        if 'fire_image' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['fire_image']
        if file.filename == '':
            flash('No selected file')
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            return fire_detector.detect('/home/fctmasterthesis/fire_app/saved_img/'+'/'+filename)
    return render_template('upload.html')

app.run(host='0.0.0.0',port='80')

While running It gives a code 500 with the following error:

ValueError: Tensor Tensor("mrcnn_detection/Reshape_1:0", shape=(1, 100, 6), dtype=float32) is not an element of this graph.

1 Answers1

1

Just run

model.keras_model._make_predict_function()

right after

model.loadweights(...)