|
def predict_image(image): |
|
try: |
|
|
|
img = image.resize((128, 128)) |
|
|
|
img = np.array(img) |
|
|
|
if img.shape == (128, 128): |
|
img = np.stack((img,) * 3, axis=-1) |
|
|
|
img = np.expand_dims(img, axis=0) / 255.0 |
|
|
|
prediction = model.predict(img) |
|
|
|
predicted_class = np.argmax(prediction) |
|
confidence = np.max(prediction) * 100 |
|
|
|
if predicted_class == 0: |
|
return f'No tumor detected. Confidence: {confidence:.2f}%' |
|
else: |
|
return f'Tumor detected. Confidence: {confidence:.2f}%' |
|
except Exception as e: |
|
return f'Error processing image: {str(e)}' |
|
|