Problem facing with tensorflow and keras in visual studio.
I have successfully pip installed tensorflow along with keras.
But somehow i am getting the following error.
ERROR: "keras" is not a known member of module "tensorflow" Pylance (reportAttributeAccessIssue).
The below is my code and the error is mentioned below of the code.
CODE:
from flask import Flask, request, jsonify
from PIL import Image
import numpy as np
import tensorflow as tf
import os
# Initialize Flask application
app = Flask(__name__)
# Load the trained model
model = tf.keras.models.load_model("trained_model.h5")
# Define route for model prediction
@app.route("/predict", methods=["POST"])
def predict():
# Check if request contains file data
if "file" not in request.files:
return jsonify({"error": "No file provided"}), 400
# Get the file from the request
file = request.files["file"]
# Save the file to a temporary location
temp_image_path = "temp_image.jpg"
file.save(temp_image_path)
# Preprocess the image
img = Image.open(temp_image_path)
img = img.resize((180, 180)) # Resize image to match model input size
img = np.array(img) / 255.0 # Normalize pixel values
img = np.expand_dims(img, axis=0) # Add batch dimension
# Make prediction
prediction = model.predict(img)
# Remove temporary image file
os.remove(temp_image_path)
# Return prediction result
return jsonify({"prediction": int(np.argmax(prediction))}), 200
# Run the Flask app
if __name__ == "__main__":
app.run(debug=True)
ERROR:
"keras" is not a known member of module "tensorflow" Pylance (reportAttributeAccessIssue)