|
Neyron tarmoq yordamida tasvirni aniqlash
|
bet | 176/182 | Sana | 19.05.2024 | Hajmi | 5,69 Mb. | | #244351 |
Bog'liq Python sun\'iy intellekt texnologiyasi Dasrlik 20241. Neyron tarmoq yordamida tasvirni aniqlash
Rasmlarni yuklash va tahlil qilish uchun Flash API:
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)
2. Neyron tarmoq yordamida ma’lumotlarga asoslangan bashorat
Kirish asosida bashorat qilish uchun Flash API:
from flask import Flask, render_template, request, jsonify
import numpy as np
import tensorflow as tf
app = Flask(__name__)
model = tf.keras.models.load_model('your_model_path.h5')
def preprocess_data(input_data):
processed_data = input_data # Misol: hozircha oldindan ishlov berilmagan
return np.array([processed_data])
def predict_data(data):
predictions = model.predict(data)
return predictions[0][0]
@app.route('/', methods=['GET’, 'POST’])
def index():
if request.method == 'POST’:
input_data = float(request.form['input_data’])
processed_data = preprocess_data(input_data)
prediction = predict_data(processed_data)
return render_template('index.html', prediction=prediction, input_data=input_data)
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
Ushbu kod Index deb nomlangan HTML shablonini taklif qiladi.sizning ehtiyojlaringizga qarab sozlashingiz mumkin bo‘lgan html.
Shuningdek, veb-ilovadagi xavfsizlik va xatolarni qayta ishlashni, shuningdek, ishlab chiqarishga joylashtirish uchun qaramlik va konfiguratsiyani boshqarishni unutmang.
Neyron tarmoqlari ma’lumotlarni qayta ishlash va naqshni aniqlash, tasniflash, regressiya va boshqalar kabi turli muammolarni hal qilish uchun kuchli vositani taqdim etadi. Ularning veb-loyihalarga integratsiyasi funksionallikni yaxshilashi va aniqroq va aqlli echimlarni taqdim etishi mumkin. Python veb-loyihalarida neyron tarmoqlardan foydalanish bo‘yicha bir necha asosiy qadamlar:
|
| |