update dataset
4
.env
|
|
@ -1,8 +1,8 @@
|
|||
# MySQL Database Configuration
|
||||
DB_HOST=localhost
|
||||
DB_PORT=3306
|
||||
DB_USER=kali
|
||||
DB_PASSWORD=asu
|
||||
DB_USER=root
|
||||
DB_PASSWORD=""
|
||||
DB_NAME=deteksi_pmk
|
||||
|
||||
# Flask Configuration
|
||||
|
|
|
|||
29
app.py
|
|
@ -13,7 +13,7 @@ from dotenv import load_dotenv
|
|||
load_dotenv()
|
||||
|
||||
from utils.helpers import load_model, estimate_prediction_confidence
|
||||
from utils.preprocessing import preprocess_image, preprocess_pipeline, validate_cattle_image
|
||||
from utils.preprocessing import preprocess_image, preprocess_pipeline, validate_cattle_image, detect_udder
|
||||
from utils.feature_extraction import FeatureExtractor
|
||||
from expert_system import ForwardChaining, KnowledgeBase # Import sistem pakar
|
||||
|
||||
|
|
@ -422,6 +422,20 @@ def _predict_single(filepath, original_filename):
|
|||
multi_enc = multiclass_model.predict(multi_scaled)[0]
|
||||
pmk_type = multiclass_label_encoder.inverse_transform([multi_enc])[0]
|
||||
|
||||
# Fallback heuristic: jika model menandai 'sehat' tapi gambar mengandung ciri ambing/puting,
|
||||
# anggap sebagai laktasi (pmk_laktasi) dan ubah prediksi agar sistem pakar terpicu.
|
||||
if prediction.lower() == 'sehat':
|
||||
try:
|
||||
udder_detected, udder_score = detect_udder(filepath)
|
||||
if udder_detected:
|
||||
prediction = 'sakit'
|
||||
pmk_type = 'pmk_laktasi'
|
||||
# update confidence minimal berdasarkan score heuristik
|
||||
confidence = max(confidence, min(udder_score * 100.0, 95.0))
|
||||
print(f"[HEURISTIC] Udder heuristic triggered for {original_filename} | score={udder_score:.2f}")
|
||||
except Exception as e:
|
||||
print(f"[HEURISTIC] Udder heuristic error: {e}")
|
||||
|
||||
features_dict = {name: float(features[i]) for i, name in enumerate(extractor.feature_names)}
|
||||
features_table = list(zip(extractor.feature_names, [round(float(x), 4) for x in features]))
|
||||
|
||||
|
|
@ -584,6 +598,10 @@ def predict():
|
|||
pmk_to_symptoms = {
|
||||
'pmk_oral': ['G02', 'G03', 'G04', 'G10', 'G14', 'G18', 'G19', 'G20', 'G21'],
|
||||
'pmk_podal': ['G05', 'G06', 'G15', 'G22', 'G23', 'G24'],
|
||||
# Udder (laktasi) — gunakan hanya gejala spesifik ambing/puting
|
||||
'pmk_laktasi': ['G07', 'G08', 'G09', 'G26', 'G27'],
|
||||
# General akut: kombinasi gejala yang menunjukkan PMK akut/menular luas
|
||||
'pmk_akut_general': ['G01', 'G02', 'G03', 'G04', 'G05', 'G06', 'G07', 'G09', 'G11', 'G12', 'G14', 'G18', 'G20', 'G22', 'G23', 'G24', 'G26']
|
||||
}
|
||||
|
||||
preselected = set()
|
||||
|
|
@ -592,6 +610,15 @@ def predict():
|
|||
if key in pmk_to_symptoms:
|
||||
preselected.update(pmk_to_symptoms[key])
|
||||
|
||||
# Jika lebih dari satu body-part berbeda terdeteksi sakit (misal: mulut+kaki, mulut+puting, kaki+puting),
|
||||
# anggap kemungkinan PMK akut/general dan preselect gejala umum akut juga.
|
||||
body_part_keys = {k for k in sick_pmk_types if k in {'pmk_oral', 'pmk_podal', 'pmk_laktasi'}}
|
||||
if len(body_part_keys) >= 2:
|
||||
# tambahkan gejala PMK akut general
|
||||
preselected.update(pmk_to_symptoms.get('pmk_akut_general', []))
|
||||
# juga tambahkan tipe pmk_akut_general ke hasil sehingga UI/riwayat menampilkan tipe ini
|
||||
sick_pmk_types.add('pmk_akut_general')
|
||||
|
||||
# Store all images in session for expert system display
|
||||
session['last_prediction'] = {
|
||||
'db_id': pred_id,
|
||||
|
|
|
|||
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 53 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 63 KiB |
|
After Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 71 KiB |
|
After Width: | Height: | Size: 63 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 182 KiB |
|
After Width: | Height: | Size: 154 KiB |
|
After Width: | Height: | Size: 177 KiB |
|
After Width: | Height: | Size: 246 KiB |
|
After Width: | Height: | Size: 182 KiB |
|
After Width: | Height: | Size: 230 KiB |
|
After Width: | Height: | Size: 206 KiB |
|
After Width: | Height: | Size: 102 KiB |
|
After Width: | Height: | Size: 127 KiB |
|
After Width: | Height: | Size: 160 KiB |
|
After Width: | Height: | Size: 154 KiB |
|
After Width: | Height: | Size: 177 KiB |
|
After Width: | Height: | Size: 143 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 248 KiB |
|
After Width: | Height: | Size: 259 KiB |
|
After Width: | Height: | Size: 113 KiB |
|
Before Width: | Height: | Size: 291 KiB After Width: | Height: | Size: 291 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 291 KiB |
|
After Width: | Height: | Size: 288 KiB |
|
After Width: | Height: | Size: 164 KiB |
|
Before Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 89 KiB |
|
After Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 9.4 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 7.4 KiB |
|
After Width: | Height: | Size: 9.7 KiB |
|
After Width: | Height: | Size: 7.2 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 8.2 KiB |
|
After Width: | Height: | Size: 8.1 KiB |
|
After Width: | Height: | Size: 32 KiB |