File size: 1,709 Bytes
2f8b452
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import streamlit as st 
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image,ImageOps
import numpy as np
import random
import cv2
import tensorflow as tf
from tensorflow import keras
from keras.models import load_model

import time 
# import mysql.connector

import process_input_pipeline as pp
import img_extractor
from process_input_pipeline import ImageResizer, ContrastEnhancer

# added for inception concat
from sklearn.pipeline import make_pipeline
from sklearn.base import BaseEstimator, TransformerMixin

import combined_model

cm = combined_model.build_regression_model()
cm.load_weights(r"F:\python\web_streamlit\ALL_IN_ONE\model_weights\model_weights\combined_weights_7_epoch_third_acc.h5")

roi=img_extractor.RoiExtractor()

def process_image(img, img_size=(224, 224)):
    try:
        new_size=(299,299)
        resized_img = img.resize(new_size, Image.BICUBIC)
        img_array=np.array(resized_img)
        clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(64, 64))
        cl1 = clahe.apply(img_array)
        cl2=cv2.cvtColor(cl1,cv2.COLOR_GRAY2BGR)
        return cl2
    except Exception as e:
        st.error(f"Error processing image: {e}")
        return None 
    
def predict(img_data_c,img_data_m, gender):
    try:
        if gender == 'Female':
            # gender_input = np.array([0])
            gender_input=0
        elif gender == 'Male':
            gender_input = 1


        pred =cm.predict([np.array([img_data_c]),np.array([img_data_m]), np.array([gender_input])])
        # pred = model.predict(img_data)
        return pred
    except Exception as e:
        st.error(f"Error predicting bone age: {e}")
        return None