Rückgabe vorhergesagte Ergebnisse in Jsonify [Duplikat]Python

Python-Programme
Anonymous
 Rückgabe vorhergesagte Ergebnisse in Jsonify [Duplikat]

Post by Anonymous »

Ich bin Student und arbeite derzeit an meinem Projekt der Bildklassifikationen in Python (Flask).
Ich habe alle Funktionen und Modelle implementiert und es funktioniert gut als Web -App. Jetzt möchte ich eine API erstellen, die zu Jsonify führt, damit ich auch in der mobilen App auch in der mobilen App verwenden kann.

Code: Select all

@app.route('/predict', methods=['GET', 'POST'])
def predict():
if request.method == 'POST':
img = request.files['image']
filename = img.filename
path = os.path.join('static/uploads', filename)
img.save(path)
print(filename)

predictions = pipeline_model(path)
return render_template("predict.html", p="uploads/{}".format(filename), pred=predictions)
return render_template("predict.html", p="images/dog.jpg", pred="")
< /code>
Die andere Pipeline -Funktion ist: < /p>
def pipeline_model(path):
img = image.load_img(path, target_size=(299, 299))
img = image.img_to_array(img)
img = img / 255.0
img = np.expand_dims(img, axis=0)

pred = model.predict(img)
max_preds = []
pred = pred[0]
for i in range(5):
name = labels[pred.argmax()]
per = round(np.amax(pred) * 100, 2)
max_preds.append([name, per])
ele = pred.argmax()
pred = np.delete(pred, ele)

paths = glob('static/uploads/*')
if len(paths) > 5:
for path in paths[:4]:
os.remove(path)
return max_preds
Ich möchte also diese Funktion "return render_template" in Form von "return Jsonify zurückgeben" konvertieren. Wie kann sie implementiert werden, damit wir sie auch in mobilen Apps verwenden können.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post