mirror of
https://github.com/arnaucube/objectImageIdentifierAI.git
synced 2026-02-08 04:06:57 +01:00
pipeline model chooser working, server predictor working
This commit is contained in:
1
other/serverPredictorOLD/.gitignore
vendored
Normal file
1
other/serverPredictorOLD/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
currentimage.png
|
||||
0
other/serverPredictorOLD/loadNN.py
Normal file
0
other/serverPredictorOLD/loadNN.py
Normal file
63
other/serverPredictorOLD/main.py
Normal file
63
other/serverPredictorOLD/main.py
Normal file
@@ -0,0 +1,63 @@
|
||||
from flask import Flask
|
||||
from flask_restful import Resource, Api, request
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import cv2
|
||||
import io
|
||||
from PIL import Image, ImageOps
|
||||
|
||||
import pickle
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16 MB
|
||||
api = Api(app)
|
||||
|
||||
size = 100, 100
|
||||
|
||||
|
||||
#load Neural Network, generated with nnTrain
|
||||
nn = pickle.load(open('nn.pkl', 'rb'))
|
||||
|
||||
class Predict(Resource):
|
||||
def get(self):
|
||||
message = {'message': 'getted route1'}
|
||||
return message
|
||||
def post(self):
|
||||
filer = request.files['file']
|
||||
#open the uploaded image, and transform to the numpy array
|
||||
filer.save("currentimage.png")
|
||||
image = Image.open("currentimage.png")
|
||||
thumb = ImageOps.fit(image, size, Image.ANTIALIAS)
|
||||
image_data = np.asarray(thumb).flatten()
|
||||
imagetopredict = np.array([image_data])
|
||||
|
||||
#predict the class of the image with the neural network
|
||||
prediction = nn.predict(imagetopredict)
|
||||
print "prediction"
|
||||
print prediction[0][0]
|
||||
if prediction[0][0]==0:
|
||||
result = "noobject"
|
||||
else:
|
||||
result = "object"
|
||||
message = {'class': result}
|
||||
return message
|
||||
|
||||
|
||||
class Route2(Resource):
|
||||
def get(self):
|
||||
return {'message': 'getted route2'}
|
||||
|
||||
|
||||
class Route3(Resource):
|
||||
def get(self):
|
||||
return {'message': 'getted route3'}
|
||||
|
||||
|
||||
api.add_resource(Predict, '/predict')
|
||||
api.add_resource(Route2, '/route2')
|
||||
api.add_resource(Route3, '/route3')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(port='3045')
|
||||
265
other/serverPredictorOLD/nn.pkl
Normal file
265
other/serverPredictorOLD/nn.pkl
Normal file
File diff suppressed because one or more lines are too long
10
other/serverPredictorOLD/test.sh
Normal file
10
other/serverPredictorOLD/test.sh
Normal file
@@ -0,0 +1,10 @@
|
||||
echo "sending img1 to server"
|
||||
echo "server response:"
|
||||
curl -F file=@./test1.png http://127.0.0.1:3045/predict
|
||||
echo ""
|
||||
|
||||
|
||||
echo "sending img2 to server"
|
||||
echo "server response:"
|
||||
curl -F file=@./test2.png http://127.0.0.1:3045/predict
|
||||
echo ""
|
||||
BIN
other/serverPredictorOLD/test1.png
Normal file
BIN
other/serverPredictorOLD/test1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 71 KiB |
BIN
other/serverPredictorOLD/test2.png
Normal file
BIN
other/serverPredictorOLD/test2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 152 KiB |
Reference in New Issue
Block a user