Forums

MLIR V1 optimization pass is not enabled

2023-01-09 06:36:33 (1, 224, 224, 3) 2023-01-09 06:36:38 2023-01-09 06:36:38.430361: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:354] MLIR V1 optimization pass is not enabled

I want to recognize fruits with python and I encountered such an error. !!!

2023-01-09 12:02:24 2023-01-09 12:02:24.465445: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:354] MLIR V1 optimization pass is not enabled
2023-01-09 12:12:15 Mon Jan  9 12:12:14 2023 - *** HARAKIRI ON WORKER 2 (pid: 24, try: 1) ***
2023-01-09 12:12:15 Mon Jan  9 12:12:14 2023 - HARAKIRI !!! worker 2 status !!!
2023-01-09 12:12:15 Mon Jan  9 12:12:14 2023 - HARAKIRI [core 0] 10.0.0.75 - POST /neyedinanaliz since 1673265733
2023-01-09 12:12:15 Mon Jan  9 12:12:14 2023 - HARAKIRI !!! end of worker 2 status !!!
2023-01-09 12:12:15 DAMN ! worker 2 (pid: 24) died, killed by signal 9 :( trying respawn ...
2023-01-09 12:12:15 Respawned uWSGI worker 2 (new pid: 34)
2023-01-09 12:12:15 spawned 2 offload threads for uWSGI worker 2

from flask import Flask, request
from flask_restful import Api, Resource
import pandas as pd
from PIL import Image
import keras
from keras import backend as K
from keras.layers.core import Dense, Flatten
from keras.preprocessing.image import ImageDataGenerator
from keras.utils import img_to_array
from flask import jsonify
import io
import numpy as np
import base64
import tensorflow as tf
from tensorflow.keras import applications
from keras import applications
from tensorflow.keras.models import Sequential
import requests

#open('model_weights.h5', 'wb').write(r.content)

app = Flask(__name__)
api = Api(app)

global image

def preprocess_image(image, target_size):
    if image.mode != "RGB":
        image = image.convert("RGB")

    image = image.resize(target_size)
    image = img_to_array(image)
    image = np.expand_dims(image, axis=0)
    print(np.shape(image))

    return image


def get_model():
    global model
    global graph
    vgg16_model = applications.vgg16.VGG16()
    model = tf.keras.Sequential()


    for i in vgg16_model.layers:
        model.add(i)


    for layer in model.layers:
        layer.trainable = False


    model.add(Dense(4, activation='softmax'))
    model.make_predict_function('model_weights.h5')
    graph = tf.compat.v1.get_default_graph()
    print("Model loaded!")


print(" Loading Keras model...")
get_model()

import csv
csvFile = 0;

with open('/home/iamonuryilmaz/mysite/csvornek.csv', mode ='r')as file:
  csvFile = csv.reader(file)
  for lines in csvFile:
          fileList = lines


class NeYedim(Resource):
      def get(self):

        data = {
            'prediction': {
            'get' : 'get işlemi',
            }
        }


        print(data)
        return {'data' : data}, 200

      #post işlemi
      def post(self):
        name = request.form['name']
        encoded = request.form['image']
        decoded = base64.b64decode(encoded)
        decode = io.BytesIO(decoded)
        image = Image.open(decode)
        image.save("/home/iamonuryilmaz/mysite/picture.jpg")
        image = Image.open("/home/iamonuryilmaz/mysite/picture.jpg")

        processed_image = preprocess_image(image, target_size=(224, 224))

        with graph.as_default():
            vgg16_model = applications.vgg16.VGG16()
            model = tf.keras.Sequential()

            for i in vgg16_model.layers:
                model.add(i)

            for layer in model.layers:
                layer.trainable = False

            model.add(Dense(4, activation='softmax'))
            model.load_weights('/home/iamonuryilmaz/mysite/model_weights.h5')
            prediction = model.predict(processed_image).tolist()

        prediction_max = max(prediction[0])
        print(prediction_max)

        id = -1
        sizeOfDemoList = len(fileList)
        for i in range(sizeOfDemoList):
            if(prediction[0][i]==prediction_max):
                id=i
        print(id)


        data = {
            'prediction': {
            'name' :  name,
            'post' : 'post işlemi',
            'sonuc': fileList[0]
            }
        }

        print(data)
        return {'data' : data}, 200

# Add URL endpoints
api.add_resource(NeYedim, '/neyedinanaliz')

if __name__ == '__main__':
#     app.run(host="0.0.0.0", port=5000)
    app.run()

Tensorflow would probably not work in a web app (see: this help page). You may consider pulling out the ML code to a task queue outside of the web app.

I want to detect the fruit in the photo sent by post request and return the result. How can I do that ?

That is not something we can help you with.