• 3-qadam: HTML shablonini yaratish
  • Tens or Flow va Flask yordamida tasvirni aniqlash




    Download 5,69 Mb.
    bet181/182
    Sana19.05.2024
    Hajmi5,69 Mb.
    #244351
    1   ...   174   175   176   177   178   179   180   181   182
    Bog'liq
    Python sun\'iy intellekt texnologiyasi Dasrlik 2024

    1. Tens or Flow va Flask yordamida tasvirni aniqlash:
    1-qadam: kutubxonalarni o‘rnatish
    pip install Flask tensorflow Pillow
    2-qadam: Flash dasturini yaratish:
    # app.py
    from flask import Flask, render_template, request, jsonify
    from PIL import Image
    import numpy as np
    import tensorflow as tf
    app = Flask(__name__)
    model = tf.keras.applications.MobileNetV2(weights='imagenet’)
    def preprocess_image(image_path):
    img = Image.open(image_path)
    img = img.resize((224, 224))
    img_array = np.array(img) / 255.0
    img_array = np.expand_dims(img_array, axis=0)
    return img_array
    def predict_image(image_array):
    predictions = model.predict(image_array)
    label = tf.keras.applications.mobilenet_v2.decode_predictions(predictions)
    return label[0][0][1]
    @app.route('/', methods=['GET’, 'POST’])
    def index():
    if request.method == 'POST’:
    file = request.files['file’]
    if file:
    image_path = "uploads/" + file.filename
    file.save(image_path)
    image_array = preprocess_image(image_path)
    prediction = predict_image(image_array)
    return render_template('index.html', prediction=prediction, image_path=image_path)
    return render_template('index.html')
    if __name__ == '__main__':
    app.run(debug=True)
    3-qadam: HTML shablonini yaratish:






    Image <a href="/yuzdan-tanib-oluvchi-face-recognition-dastur-yarating.html">Recognition</a>


    Image Recognition






    {% if prediction %}

    Download 5,69 Mb.
    1   ...   174   175   176   177   178   179   180   181   182




    Download 5,69 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Tens or Flow va Flask yordamida tasvirni aniqlash

    Download 5,69 Mb.