hakim commited on
Commit
00004c2
·
1 Parent(s): 202fe17

important file added

Browse files
Files changed (12) hide show
  1. .dvcignore +3 -0
  2. .gitignore +1 -0
  3. Dockerfile +11 -0
  4. README.md +64 -1
  5. app.py +75 -0
  6. dvc.yaml +55 -0
  7. main.py +54 -0
  8. params.yaml +8 -0
  9. requirements.txt +17 -0
  10. scores.json +4 -0
  11. setup.py +30 -0
  12. template.py +43 -0
.dvcignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Add patterns of files dvc should ignore, which could improve
2
+ # the performance. Learn more at
3
+ # https://dvc.org/doc/user-guide/dvcignore
.gitignore CHANGED
@@ -160,3 +160,4 @@ cython_debug/
160
  # and can be added to the global gitignore or merged into this file. For a more nuclear
161
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
  #.idea/
 
 
160
  # and can be added to the global gitignore or merged into this file. For a more nuclear
161
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
  #.idea/
163
+ artifacts/*
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . /code
10
+
11
+ CMD ["streamlit", "run", "app.py"]
README.md CHANGED
@@ -1 +1,64 @@
1
- # Chicken-disease-classification
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+ title: Image To Text App
4
+ emoji: 📹
5
+ colorFrom: blue
6
+ colorTo: red
7
+ sdk: streamlit
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+ ## Workflows
12
+
13
+ 1. Update config.yaml
14
+ 2. Update secrets.yaml [Optional]
15
+ 3. Update params.yaml
16
+ 4. Update the entity
17
+ 5. Update the configuration manager in src config
18
+ 6. Update the components
19
+ 7. Update the pipeline
20
+ 8. Update the main.py
21
+ 9. Update the dvc.yaml
22
+
23
+
24
+ # How to run?
25
+ ### STEPS:
26
+
27
+ Clone the repository
28
+
29
+ ```bash
30
+ https://github.com/HAKIM-ML/Chicken-Disease-Classification-Using-Mlops
31
+ ```
32
+ ### STEP 01- Create a conda environment after opening the repository
33
+
34
+ ```bash
35
+ conda create -n cnncls python=3.8 -y
36
+ ```
37
+
38
+ ```bash
39
+ conda activate cnncls
40
+ ```
41
+
42
+
43
+ ### STEP 02- install the requirements
44
+ ```bash
45
+ pip install -r requirements.txt
46
+ ```
47
+
48
+
49
+ ```bash
50
+ # Finally run the following command
51
+ python app.py
52
+ ```
53
+
54
+ Now,
55
+ ```bash
56
+ open up you local host and port
57
+ ```
58
+
59
+
60
+ ### DVC cmd
61
+
62
+ 1. dvc init
63
+ 2. dvc repro
64
+ 3. dvc dag
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import io
4
+ from PIL import Image
5
+ import os
6
+ from src.cnnClassfier.pipeline.predict import Prediction
7
+
8
+ st.set_page_config(page_title="Chicken Health Predictor", page_icon="🐔", layout="wide")
9
+
10
+ st.title("🐔 Chicken Health Predictor")
11
+ st.markdown("### Upload an image to predict if the chicken is healthy or has coccidiosis")
12
+
13
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
14
+
15
+ col1, col2 = st.columns(2)
16
+
17
+ if uploaded_file is not None:
18
+ image = Image.open(uploaded_file)
19
+ col1.image(image, caption="Uploaded Image", use_column_width=True)
20
+
21
+ # Save the uploaded file temporarily
22
+ temp_file = "temp_image.jpg"
23
+ image.save(temp_file)
24
+
25
+ with st.spinner("Analyzing the image..."):
26
+ predictor = Prediction(temp_file)
27
+ prediction = predictor.predict()
28
+
29
+ # Remove the temporary file
30
+ os.remove(temp_file)
31
+
32
+ col2.markdown("## Prediction Result")
33
+ if prediction == "Healthy":
34
+ col2.success(f"The chicken appears to be **{prediction}**! 🎉")
35
+ col2.markdown("Keep up the good care for your feathered friend!")
36
+ else:
37
+ col2.error(f"The chicken may have **{prediction}**. 😢")
38
+ col2.markdown("Please consult with a veterinarian for proper treatment.")
39
+
40
+ col2.markdown("### What is Coccidiosis?")
41
+ col2.info("""
42
+ Coccidiosis is a parasitic disease of the intestinal tract of animals caused by coccidian protozoa.
43
+ The disease spreads from one animal to another by contact with infected feces or ingestion of infected tissue.
44
+ Diarrhea, which may become bloody in severe cases, is the primary symptom.
45
+ """)
46
+
47
+ st.sidebar.title("About")
48
+ st.sidebar.info(
49
+ "This app uses a deep learning model to predict whether a chicken is healthy "
50
+ "or has coccidiosis based on an uploaded image. Always consult with a "
51
+ "veterinarian for accurate diagnosis and treatment."
52
+ )
53
+
54
+ st.sidebar.title("Instructions")
55
+ st.sidebar.markdown(
56
+ """
57
+ 1. Upload a clear image of a chicken.
58
+ 2. Wait for the model to analyze the image.
59
+ 3. View the prediction result and additional information.
60
+ """
61
+ )
62
+
63
+ st.markdown(
64
+ """
65
+ <style>
66
+ .reportview-container {
67
+ background: linear-gradient(to right, #FDFCFB, #E2D1C3);
68
+ }
69
+ .sidebar .sidebar-content {
70
+ background: linear-gradient(to bottom, #FDFCFB, #E2D1C3);
71
+ }
72
+ </style>
73
+ """,
74
+ unsafe_allow_html=True,
75
+ )
dvc.yaml ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ stages:
2
+ data_ingestion:
3
+ cmd: python src/cnnClassfier/pipeline/stage_01_data_ingestion.py
4
+ deps:
5
+ - src/cnnClassfier/pipeline/stage_01_data_ingestion.py
6
+ - config/config.yaml
7
+ outs:
8
+ - artifacts/data_ingestion/Chicken-fecal-images
9
+
10
+
11
+ prepare_base_model:
12
+ cmd: python src/cnnClassfier/pipeline/stage02_base_model.py
13
+ deps:
14
+ - src/cnnClassfier/pipeline/stage02_base_model.py
15
+ - config/config.yaml
16
+ params:
17
+ - IMAZE_SIZE
18
+ - INCLUDE_TOP
19
+ - CLASSES
20
+ - WEIGHTS
21
+ - LEARNING_RATE
22
+ outs:
23
+ - artifacts/prepare_base_model
24
+
25
+
26
+ training:
27
+ cmd: python src/cnnClassfier/pipeline/stage_03_train.py
28
+ deps:
29
+ - src/cnnClassfier/pipeline/stage_03_train.py
30
+ - src/cnnClassfier/components/callbacks.py
31
+ - config/config.yaml
32
+ - artifacts/data_ingestion/Chicken-fecal-images
33
+ - artifacts/prepare_base_model
34
+ params:
35
+ - IMAZE_SIZE
36
+ - EPOCHS
37
+ - BATCH_SIZE
38
+ - AUGMENTATION
39
+ outs:
40
+ - artifacts/training/model.h5
41
+
42
+
43
+ evaluation:
44
+ cmd: python src/cnnClassfier/pipeline/stage_04_evaluation.py
45
+ deps:
46
+ - src/cnnClassfier/pipeline/stage_04_evaluation.py
47
+ - config/config.yaml
48
+ - artifacts/data_ingestion/Chicken-fecal-images
49
+ - artifacts/training/model.h5
50
+ params:
51
+ - IMAZE_SIZE
52
+ - BATCH_SIZE
53
+ metrics:
54
+ - scores.json:
55
+ cache: false
main.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from cnnClassfier import logger
2
+ from cnnClassfier.pipeline.stage_01_data_ingestion import DataIngestionTrainingPipeline
3
+ from cnnClassfier.pipeline.stage02_base_model import PrepareBaseModelTrainigPipeline
4
+ from cnnClassfier.pipeline.stage_03_train import ModelTrainingPipeline
5
+ from cnnClassfier.pipeline.stage_04_evaluation import EvaluationTrainigPipeline
6
+
7
+
8
+ STAGE_NAME = "Data Ingestion Stage"
9
+
10
+ try:
11
+ logger.info(f">>>>>> Stage {STAGE_NAME} Started >>>>>>")
12
+ data_ingestion = DataIngestionTrainingPipeline()
13
+ data_ingestion.main()
14
+ logger.info(f"<<<<<< Stage {STAGE_NAME} Completed >>>>>>")
15
+ except Exception as e:
16
+ logger.exception(e)
17
+ raise e
18
+
19
+
20
+ STAGE_NAME = "Prepare Base Model"
21
+
22
+ try:
23
+ logger.info(f">>>>>> Stage {STAGE_NAME} Started >>>>>>")
24
+ base_model = PrepareBaseModelTrainigPipeline()
25
+ base_model.main()
26
+ logger.info(f"<<<<<< Stage {STAGE_NAME} Completed >>>>>>")
27
+ except Exception as e:
28
+ logger.exception(e)
29
+ raise e
30
+
31
+
32
+ STAGE_NAME = "Model Trainig"
33
+
34
+ try:
35
+ logger.info(f">>>>>> Stage {STAGE_NAME} Started >>>>>>")
36
+ model_trainer = ModelTrainingPipeline()
37
+ model_trainer.main()
38
+ logger.info(f"<<<<<< Stage {STAGE_NAME} Completed >>>>>>")
39
+ except Exception as e:
40
+ logger.exception(e)
41
+ raise e
42
+
43
+
44
+ STAGE_NAME = "Model Evaluation"
45
+
46
+ try:
47
+ logger.info(f">>>>>> Stage {STAGE_NAME} Started >>>>>>")
48
+ model_evaluation = EvaluationTrainigPipeline()
49
+ model_evaluation.main()
50
+ logger.info(f"<<<<<< Stage {STAGE_NAME} Completed >>>>>>")
51
+ except Exception as e:
52
+ logger.exception(e)
53
+ raise e
54
+
params.yaml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ AUGMENTATION : True
2
+ IMAZE_SIZE : [224,224,3]
3
+ BATCH_SIZE: 16
4
+ INCLUDE_TOP: FALSE
5
+ EPOCHS : 1
6
+ CLASSES : 2
7
+ WEIGHTS: imagenet
8
+ LEARNING_RATE : 0.01
requirements.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pandas
2
+ dvc
3
+ notebook
4
+ numpy
5
+ matplotlib
6
+ seaborn
7
+ python-box==6.0.2
8
+ pyYAML
9
+ tqdm
10
+ ensure==1.0.2
11
+ joblib
12
+ types-PyYAML
13
+ scipy
14
+ Flask
15
+ Flask-Cors
16
+ tensorflow==2.15.0
17
+ streamlit
scores.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "loss": 8.425772666931152,
3
+ "accuracy": 0.5
4
+ }
setup.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import setuptools
2
+
3
+ with open("README.md", "r", encoding="utf-8") as f:
4
+ long_description = f.read()
5
+
6
+
7
+ __version__ = "0.0.0"
8
+
9
+ REPO_NAME = "Chicken-disease-classification"
10
+ AUTHOR_USER_NAME = "HAKIM-ML"
11
+ SRC_REPO = "cnnClassifier"
12
+ AUTHOR_EMAIL = "akborislamamir5555@gmail.com"
13
+
14
+
15
+ setuptools.setup(
16
+ name=SRC_REPO,
17
+ version=__version__,
18
+ author=AUTHOR_USER_NAME,
19
+ author_email=AUTHOR_EMAIL,
20
+ description="A small python package for CNN app",
21
+ long_description=long_description,
22
+ long_description_content="text/markdown",
23
+ url=f"https://github.com/{AUTHOR_USER_NAME}/{REPO_NAME}",
24
+ project_urls={
25
+ "Bug Tracker": f"https://github.com/{AUTHOR_USER_NAME}/{REPO_NAME}/issues",
26
+ },
27
+ package_dir={"": "src"},
28
+ packages=setuptools.find_packages(where="src")
29
+
30
+ )
template.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pathlib import Path
3
+ import logging
4
+
5
+ logging.basicConfig(level=logging.INFO, format='[%(asctime)s]: (message)s:')
6
+
7
+ project_name = 'cnnClassfier'
8
+
9
+ list_of_files = [
10
+ '.github/workflows/.gitkeep',
11
+ f"src/{project_name}/__init__.py",
12
+ f"src/{project_name}/components/__init__.py",
13
+ f"src/{project_name}/utils/__init__.py",
14
+ f"src/{project_name}/config/__init__.py",
15
+ f"src/{project_name}/config/configuration.py",
16
+ f"src/{project_name}/pipeline/__init__.py",
17
+ f"src/{project_name}/entity/__init__.py",
18
+ f"src/{project_name}/constants/__init__.py",
19
+ "config/config.yaml",
20
+ 'dvc.yaml',
21
+ 'params.yaml',
22
+ 'requirements.txt',
23
+ 'setup.py',
24
+ 'research./tails.ipynb',
25
+
26
+ ]
27
+
28
+ for filepath in list_of_files:
29
+ filepath = Path(filepath)
30
+ fildir, file_name = os.path.split(filepath)
31
+
32
+
33
+ if fildir != '':
34
+ os.makedirs(fildir, exist_ok=True)
35
+ logging.info(f"creating directory: {fildir} for the file: {file_name}")
36
+
37
+ if (not os.path.exists(filepath)) or (os.path.getsize(filepath) == 0):
38
+ with open(filepath, 'w') as f:
39
+ pass
40
+ logging.info(f"Creating empty file: {filepath}")
41
+
42
+ else:
43
+ logging.info(f"{file_name} is already exists")