Skip to content

Add Plant Disease Classification (CNN) project#4

Open
ARUNAGIRINATHAN-K wants to merge 12 commits into
tkarim45:mainfrom
Aetherion-dotcom:main
Open

Add Plant Disease Classification (CNN) project#4
ARUNAGIRINATHAN-K wants to merge 12 commits into
tkarim45:mainfrom
Aetherion-dotcom:main

Conversation

@ARUNAGIRINATHAN-K

@ARUNAGIRINATHAN-K ARUNAGIRINATHAN-K commented Apr 9, 2026

Copy link
Copy Markdown

This PR adds a new beginner-friendly computer vision project: Plant Disease Classification Using CNNs, deployed as a Hugging Face Space.

What’s included:

  • Project entry with brief summary and learning outcomes
  • Link to the GitHub repository: GitHub
  • Hugging Face : demo

This Provides a practical end-to-end example of image classification from notebook experimentation to deployment suitable for beginners exploring CNNs and applied ML.

Checklist:

  • Added project to the appropriate list/section
  • Verified links work
  • Kept formatting consistent with repository guidelines

Summary by CodeRabbit

  • New Features

    • Web app for plant disease image classification with EfficientNet-B0 and Gradio UI
    • Returns an annotated image plus top prediction and confidence
  • Documentation

    • Added README with demo, dataset and usage details
    • Added EfficientNet workflow guide covering model setup, transforms, and fine‑tuning
    • Included class label list (~38 plant disease categories)
  • Chores

    • Added dependency list, Apache‑2.0 license, and Git LFS configuration for large assets

@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e87af51a-262a-4e7e-87d1-78e6236a167d

📥 Commits

Reviewing files that changed from the base of the PR and between 99e6cf8 and f5f7d75.

📒 Files selected for processing (1)
  • Plant Disease CNNs/app.py

📝 Walkthrough

Walkthrough

Adds a Plant Disease Classification project: Git LFS rules, dependency list, Apache-2.0 license, documentation (README, EfficientNet guide), class label JSON, and a Gradio EfficientNet-B0 inference app that loads a checkpoint and returns annotated predictions.

Changes

Cohort / File(s) Summary
VCS config
Plant Disease CNNs/.gitattributes
New Git LFS patterns marking common ML/data artifacts (models, arrays, archives, event files) as binary and routed through LFS.
Dependencies
Plant Disease CNNs/requirements.txt
Adds project dependency list (torch, torchvision, timm, gradio, pillow, numpy, matplotlib).
Documentation & License
Plant Disease CNNs/README.md, Plant Disease CNNs/EfficientNet.md, Plant Disease CNNs/LICENSE
Adds README with project overview and Hugging Face Spaces info, an EfficientNet usage/fine-tuning guide, and an Apache-2.0 LICENSE file.
App & data
Plant Disease CNNs/app.py, Plant Disease CNNs/class_names.json
Adds Gradio inference app: device selection, EfficientNet-B0 instantiation via timm, strict checkpoint load, preprocessing, predict(image) producing annotated image and Markdown result; adds class label list JSON.

Sequence Diagram

sequenceDiagram
    participant User as "User"
    participant UI as "Gradio UI"
    participant App as "app.py"
    participant FS as "File System"
    participant Model as "EfficientNet-B0"
    participant Device as "Device (CUDA/CPU)"

    User->>UI: open app / upload image
    UI->>App: predict(image)
    App->>FS: read `class_names.json` and checkpoint
    FS-->>App: return labels and weights
    App->>Model: instantiate via `timm` (num_classes)
    App->>Device: move model, set eval()
    App->>Model: preprocess image → forward pass
    Model-->>App: logits
    App->>App: softmax → top class + confidence, create annotated image
    App->>UI: return annotated image + Markdown
    UI-->>User: display results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through bytes and leafy greens,
I learned the names of tiny scenes,
A net, a snap, a confident cheer—
I paint the guess that brings you near,
🌿🥕 — from a rabbit who codes with glee

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a new Plant Disease Classification CNN project to the repository.
Description check ✅ Passed The description addresses most template requirements: includes a project summary, learning objectives, and relevant links. However, the repository template checklist is not fully completed as described in the PR description itself.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🧹 Nitpick comments (3)
Plant Disease CNNs/class_names.json (1)

1-1: Consider formatting JSON for readability.

The single-line JSON is valid but difficult to read and maintain. Consider formatting with one class per line and adding a trailing newline.

✨ Suggested format (excerpt)
[
  "Apple___Apple_scab",
  "Apple___Black_rot",
  "Apple___Cedar_apple_rust",
  ...
  "Tomato___healthy"
]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Plant` Disease CNNs/class_names.json at line 1, The class_names.json file is
a single-line JSON array which is hard to read; reformat the JSON in
class_names.json (the array of class strings like "Apple___Apple_scab",
"Tomato___healthy", etc.) to pretty-printed form with one class per line, proper
indentation and a trailing newline at EOF so the file is more maintainable and
diff-friendly.
Plant Disease CNNs/app.py (2)

7-8: Unused imports.

torch.nn (line 7) is imported but never used. torch.nn.functional (line 8) is used for F.softmax.

✨ Suggested fix
 from PIL import Image
-import torch.nn as nn
 import torch.nn.functional as F
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Plant` Disease CNNs/app.py around lines 7 - 8, The import of torch.nn is
unused while torch.nn.functional is used via the alias F for F.softmax; remove
the unused torch.nn import to clean up imports and keep only the functional
import (e.g., ensure F is imported as torch.nn.functional and delete the unused
torch.nn import symbol) so references like F.softmax continue to work and no
unused-import warnings remain.

17-18: Missing error handling for file loading.

If class_names.json or efficientnet_plant_best.pth is missing, the app will crash with an unhelpful error. Consider adding descriptive error handling for better debugging, especially in deployment environments.

✨ Example improvement
import os

CLASS_NAMES_PATH = "class_names.json"
MODEL_PATH = "efficientnet_plant_best.pth"

if not os.path.exists(CLASS_NAMES_PATH):
    raise FileNotFoundError(f"Class names file not found: {CLASS_NAMES_PATH}")
if not os.path.exists(MODEL_PATH):
    raise FileNotFoundError(f"Model weights not found: {MODEL_PATH}")

Also applies to: 31-34

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Plant` Disease CNNs/app.py around lines 17 - 18, The code opens
"class_names.json" and loads model weights without checks, causing unhelpful
crashes; update the block that sets class_names and the model-loading logic
(references: class_names, "class_names.json", and the model weight path
"efficientnet_plant_best.pth"/where torch.load is called) to first verify the
files exist (os.path.exists) and either raise a clear FileNotFoundError or log a
descriptive error and exit; additionally wrap the json.load and model load in
try/except to catch and surface JSONDecodeError or torch loading errors with
contextual messages so failures are informative in deployment.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Plant` Disease CNNs/app.py:
- Around line 96-111: Remove the redundant blocking call to interface.launch()
so the Gradio Blocks UI (with demo) can run; delete the interface.launch() line
and ensure only demo.launch() is used. Also fix the output mapping for
btn.click: update the outputs list to match predict()'s return values
(annotated_img and result_text) and replace the single output_label (gr.Label())
with the correct components (e.g., an Image component for annotated_img and a
Label/Text component for result_text) so btn.click(predict, inputs=input_image,
outputs=...) matches predict's return tuple.

In `@Plant` Disease CNNs/EfficientNet.md:
- Around line 3-5: The README/section has mixed references to EfficientNetB3 and
B0 while the code (app.py) constructs the model using efficientnet_b0; update
the documentation to be consistent by either (a) changing the header and any B3
mentions to reference EfficientNet-B0 (or "EfficientNet-B0") and noting that the
project uses timm's efficientnet_b0 in app.py, or (b) if you intend to use B3,
modify app.py to instantiate efficientnet_b3 instead—ensure all mentions of
EfficientNetB3, EfficientNet-B0, and the timm model name efficientnet_b0 in the
docs and code match.
- Around line 20-22: The Markdown code fence around the pip install command uses
the wrong language tag; update the fenced code block containing "pip install
timm" (the triple-backtick block) to use a shell/bash language tag by replacing
```python with ```bash so the command is correctly highlighted and rendered.
- Around line 88-90: The Markdown code fence around the Python snippet is
malformed (it closes with four backticks). Edit the block that contains the line
"optimizer = torch.optim.AdamW(model.parameters(), lr=1e-5)" to use a standard
triple-backtick fence (``` ) for both opening and closing, replacing the
four-backtick closing fence with three backticks so the snippet renders
correctly.

In `@Plant` Disease CNNs/README.md:
- Around line 15-28: The README's "Transformers" examples (pipeline,
AutoModel.from_pretrained) are misleading because the repo's app.py uses timm
and Gradio directly and does not import transformers; either clarify these
snippets are optional examples for a separately published HF model or remove
them and update requirements.txt to drop transformers; specifically edit
README.md to state that pipeline and AutoModel usage are for a separately
published Hugging Face model (or delete that section), and if you remove the
examples, remove transformers from requirements.txt and/or note in app.py why
transformers is not used while timm and Gradio are required.
- Around line 77-84: The README.md currently contains Hugging Face Spaces YAML
frontmatter (title: LeafDiseaseML, sdk_version: 6.8.0, app_file: app.py, pinned:
false) placed mid/bottom and without proper --- delimiters; move a proper
frontmatter block to the very top of README.md (before the "# 🌿 Plant Disease
Classification" header), wrap it with --- delimiters, and include required keys
such as title: LeafDiseaseML, emoji, sdk: gradio, sdk_version: 6.8.0, app_file:
app.py, colorFrom/colorTo, and pinned: false so HF Spaces can parse it.
- Around line 63-66: The README currently claims EfficientNetB3 and
TensorFlow/Keras, but the implementation (see app.py) instantiates
efficientnet_b0 via timm and uses PyTorch; update the README to reflect the real
implementation by replacing "EfficientNetB3" with "EfficientNet-B0", replace
"TensorFlow / Keras" with "PyTorch (timm)", and ensure the Tech Stack table and
the quick model summary match app.py's actual symbols (efficientnet_b0, timm,
PyTorch) so documentation and code are consistent.

In `@Plant` Disease CNNs/requirements.txt:
- Around line 1-8: Update the requirements file to match actual imports used by
the app: add gradio because app.py imports and uses it (ensure correct version
if needed), remove the duplicate numpy entry so it appears only once, and remove
transformers since app.py does not import or use it to avoid unnecessary
installs; verify torch/torchvision/timm/pillow/matplotlib remain as required by
the code.

---

Nitpick comments:
In `@Plant` Disease CNNs/app.py:
- Around line 7-8: The import of torch.nn is unused while torch.nn.functional is
used via the alias F for F.softmax; remove the unused torch.nn import to clean
up imports and keep only the functional import (e.g., ensure F is imported as
torch.nn.functional and delete the unused torch.nn import symbol) so references
like F.softmax continue to work and no unused-import warnings remain.
- Around line 17-18: The code opens "class_names.json" and loads model weights
without checks, causing unhelpful crashes; update the block that sets
class_names and the model-loading logic (references: class_names,
"class_names.json", and the model weight path
"efficientnet_plant_best.pth"/where torch.load is called) to first verify the
files exist (os.path.exists) and either raise a clear FileNotFoundError or log a
descriptive error and exit; additionally wrap the json.load and model load in
try/except to catch and surface JSONDecodeError or torch loading errors with
contextual messages so failures are informative in deployment.

In `@Plant` Disease CNNs/class_names.json:
- Line 1: The class_names.json file is a single-line JSON array which is hard to
read; reformat the JSON in class_names.json (the array of class strings like
"Apple___Apple_scab", "Tomato___healthy", etc.) to pretty-printed form with one
class per line, proper indentation and a trailing newline at EOF so the file is
more maintainable and diff-friendly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7794bd20-9b5e-46e0-8a98-f91b8785fd97

📥 Commits

Reviewing files that changed from the base of the PR and between 049c970 and 165ff7a.

⛔ Files ignored due to path filters (8)
  • Plant Disease CNNs/img/__results___15_0.png is excluded by !**/*.png
  • Plant Disease CNNs/img/__results___16_0.png is excluded by !**/*.png
  • Plant Disease CNNs/img/__results___16_1.png is excluded by !**/*.png
  • Plant Disease CNNs/img/__results___16_2.png is excluded by !**/*.png
  • Plant Disease CNNs/img/__results___16_3.png is excluded by !**/*.png
  • Plant Disease CNNs/img/__results___16_4.png is excluded by !**/*.png
  • Plant Disease CNNs/img/demo.gif is excluded by !**/*.gif
  • Plant Disease CNNs/img/flow1.png is excluded by !**/*.png
📒 Files selected for processing (8)
  • Plant Disease CNNs/.gitattributes
  • Plant Disease CNNs/EfficientNet.md
  • Plant Disease CNNs/LICENSE
  • Plant Disease CNNs/README.md
  • Plant Disease CNNs/app.py
  • Plant Disease CNNs/class_names.json
  • Plant Disease CNNs/plant-disease-cnn.ipynb
  • Plant Disease CNNs/requirements.txt

Comment thread Plant Disease CNNs/app.py Outdated
Comment thread Plant Disease CNNs/EfficientNet.md Outdated
Comment thread Plant Disease CNNs/EfficientNet.md Outdated
Comment thread Plant Disease CNNs/EfficientNet.md Outdated
Comment thread Plant Disease CNNs/README.md Outdated
Comment thread Plant Disease CNNs/README.md Outdated
Comment thread Plant Disease CNNs/README.md Outdated
Comment thread Plant Disease CNNs/requirements.txt Outdated
Copilot AI and others added 3 commits April 9, 2026 04:02
…-launch-call

Fix Plant Disease CNNs: align docs/code to EfficientNet-B0, clean up requirements and imports

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
Plant Disease CNNs/README.md (1)

37-40: ⚠️ Potential issue | 🟠 Major

Fix the direct-load Transformers example.

AutoModel.from_pretrained(..., dtype="auto") is not the task-specific loader for an image-classification checkpoint, and dtype is not the usual PyTorch from_pretrained kwarg here. Copying this snippet will likely give readers the wrong model class or a runtime error.

Suggested fix
-# Load model directly
-from transformers import AutoModel
-model = AutoModel.from_pretrained("ARUNAGIRINATHAN/plant_disease", dtype="auto")
+# Load model directly
+from transformers import AutoImageProcessor, AutoModelForImageClassification
+
+processor = AutoImageProcessor.from_pretrained("ARUNAGIRINATHAN/plant_disease")
+model = AutoModelForImageClassification.from_pretrained(
+    "ARUNAGIRINATHAN/plant_disease",
+    torch_dtype="auto",
+)
For Hugging Face Transformers image classification models, is `AutoModel.from_pretrained(..., dtype="auto")` a valid direct-loading example, or should documentation use `AutoModelForImageClassification` with `torch_dtype` (and typically `AutoImageProcessor`) instead?
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Plant` Disease CNNs/README.md around lines 37 - 40, The example incorrectly
uses AutoModel.from_pretrained(..., dtype="auto") for an image-classification
checkpoint; replace it with the task-specific loader
AutoModelForImageClassification and load the processor with AutoImageProcessor,
and if a dtype hint is needed use the PyTorch kwarg torch_dtype when calling
AutoModelForImageClassification.from_pretrained; update the snippet to use
AutoImageProcessor.from_pretrained(...) and
AutoModelForImageClassification.from_pretrained(..., torch_dtype=...) so readers
get the correct model class and processor for image classification.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Plant` Disease CNNs/app.py:
- Around line 45-46: The predict function should validate the input before
calling transform(image): check that the image is not None and is a valid
non-empty file/object (e.g., PIL Image or bytes) and if invalid return/raise a
clear validation error (e.g., ValueError or a Flask/fastAPI-friendly error)
instead of calling transform; update predict (and any callers) to perform this
guard before img_tensor = transform(image).unsqueeze(0).to(device) so the UI
receives a descriptive validation message rather than a backend error.
- Around line 16-31: The code opens "class_names.json" and loads
"efficientnet_plant_best.pth" using relative paths which fail if the working
directory isn't the app.py folder; change these to resolve paths relative to the
app.py file (use the module file location, e.g. Path(__file__).resolve().parent)
and build absolute paths for the class_names.json open and for torch.load so
timm.create_model and model.load_state_dict still use the same model/num_classes
but the asset lookups use the resolved paths to the files.

---

Duplicate comments:
In `@Plant` Disease CNNs/README.md:
- Around line 37-40: The example incorrectly uses AutoModel.from_pretrained(...,
dtype="auto") for an image-classification checkpoint; replace it with the
task-specific loader AutoModelForImageClassification and load the processor with
AutoImageProcessor, and if a dtype hint is needed use the PyTorch kwarg
torch_dtype when calling AutoModelForImageClassification.from_pretrained; update
the snippet to use AutoImageProcessor.from_pretrained(...) and
AutoModelForImageClassification.from_pretrained(..., torch_dtype=...) so readers
get the correct model class and processor for image classification.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4a7f09a0-02f5-4e65-99e4-1a4d47082d8e

📥 Commits

Reviewing files that changed from the base of the PR and between 165ff7a and 4c4074e.

📒 Files selected for processing (5)
  • Plant Disease CNNs/EfficientNet.md
  • Plant Disease CNNs/README.md
  • Plant Disease CNNs/app.py
  • Plant Disease CNNs/class_names.json
  • Plant Disease CNNs/requirements.txt
✅ Files skipped from review due to trivial changes (3)
  • Plant Disease CNNs/requirements.txt
  • Plant Disease CNNs/class_names.json
  • Plant Disease CNNs/EfficientNet.md

Comment thread Plant Disease CNNs/app.py Outdated
Comment thread Plant Disease CNNs/app.py

@ARUNAGIRINATHAN-K ARUNAGIRINATHAN-K left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All mentioned error and conflicts are solved

Copilot AI and others added 2 commits April 10, 2026 04:06
…hs-in-cnn-app

fix: resolve asset paths relative to __file__ in Plant Disease CNNs app

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
Plant Disease CNNs/app.py (1)

49-50: ⚠️ Potential issue | 🟠 Major

Restore the empty-upload guard in predict().

Line 50 still dereferences image unconditionally, so an empty submission falls through to transform() and fails as a backend error instead of a clear user message.

Suggested fix
 def predict(image):
+    if image is None:
+        raise ValueError("Please upload a leaf image before running prediction.")
     img_tensor = transform(image).unsqueeze(0).to(device)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Plant` Disease CNNs/app.py around lines 49 - 50, The predict(image) function
currently dereferences image unconditionally; add an empty-upload guard at the
top of predict to check for a missing/empty image (e.g., if image is None or
otherwise falsy) and return or raise a clear error (e.g., raise ValueError or
return an error response) before calling transform(image). Ensure the guard sits
before the existing img_tensor = transform(image).unsqueeze(0).to(device) line
so transform is never called with an empty input.
🧹 Nitpick comments (1)
Plant Disease CNNs/app.py (1)

88-97: Remove the unused gr.Interface definition.

The Interface object (lines 88-97) is never instantiated or launched—only demo.launch() is called. This leaves dead code that duplicates the same inference contract as the Blocks UI and creates unnecessary maintenance burden.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Plant` Disease CNNs/app.py around lines 88 - 97, Remove the dead gr.Interface
definition that creates an unused "interface" variable (the block calling
gr.Interface with fn=predict and image/markdown outputs); delete that entire
declaration so only the Blocks-based UI (the existing demo and its demo.launch
call) remains; ensure the predict function is still referenced only by the
Blocks components and that no other code depends on the removed "interface"
variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@Plant` Disease CNNs/app.py:
- Around line 49-50: The predict(image) function currently dereferences image
unconditionally; add an empty-upload guard at the top of predict to check for a
missing/empty image (e.g., if image is None or otherwise falsy) and return or
raise a clear error (e.g., raise ValueError or return an error response) before
calling transform(image). Ensure the guard sits before the existing img_tensor =
transform(image).unsqueeze(0).to(device) line so transform is never called with
an empty input.

---

Nitpick comments:
In `@Plant` Disease CNNs/app.py:
- Around line 88-97: Remove the dead gr.Interface definition that creates an
unused "interface" variable (the block calling gr.Interface with fn=predict and
image/markdown outputs); delete that entire declaration so only the Blocks-based
UI (the existing demo and its demo.launch call) remains; ensure the predict
function is still referenced only by the Blocks components and that no other
code depends on the removed "interface" variable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6fcabc4e-1b44-4d73-ad12-f2dc3989879f

📥 Commits

Reviewing files that changed from the base of the PR and between 4c4074e and 061fe24.

📒 Files selected for processing (1)
  • Plant Disease CNNs/app.py

Copilot AI and others added 2 commits April 10, 2026 04:35
…tion-empty-guard

fix(plant-disease-cnns): guard against empty image input and remove dead gr.Interface

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Plant` Disease CNNs/app.py:
- Around line 49-53: The predict function may receive RGBA or grayscale images
so transform(image) can produce tensors with 4 or 1 channels, breaking
EfficientNet-B0's 3-channel input; before applying transform in predict, convert
the PIL/ndarray image to RGB (e.g., image = image.convert("RGB") for PIL or use
cv2/canvases to convert arrays) to guarantee 3 channels, then proceed with
img_tensor = transform(image).unsqueeze(0).to(device); ensure this conversion
happens inside predict and covers both PIL Image and numpy array inputs when
present.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2ae94e3f-688f-4486-8868-319af328a5a0

📥 Commits

Reviewing files that changed from the base of the PR and between 061fe24 and 99e6cf8.

📒 Files selected for processing (1)
  • Plant Disease CNNs/app.py

Comment thread Plant Disease CNNs/app.py
Copilot AI and others added 2 commits April 10, 2026 15:22
…l-handling

Fix RGBA/grayscale image channel mismatch in Plant Disease CNN predict

@tkarim45 tkarim45 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, @ARUNAGIRINATHAN-K — and for the patient back-and-forth with CodeRabbit. The training notebook, Gradio app, and EfficientNet docs all look good. CI is green.

One optional doc cleanup before/after merge:

  • Plant Disease CNNs/README.md:37-40 — the "Load model directly" snippet uses AutoModel.from_pretrained(..., dtype="auto"), which won't load an image-classification head. Since the README correctly notes that the local app.py doesn't depend on transformers, this is purely informational for users wanting to load your published HF model — but the snippet as written would fail. Suggested:

    from transformers import AutoImageProcessor, AutoModelForImageClassification
    processor = AutoImageProcessor.from_pretrained("ARUNAGIRINATHAN/plant_disease")
    model = AutoModelForImageClassification.from_pretrained(
        "ARUNAGIRINATHAN/plant_disease",
        torch_dtype="auto",
    )

Happy to merge as-is if you'd rather fix this in a follow-up. Nice work!

@Aetherion-dotcom

Aetherion-dotcom commented May 6, 2026

Copy link
Copy Markdown

@tkarim45
Thanks for reviewing the PR and for pointing out the README snippet! You’re right AutoModel.from_pretrained(..., dtype="auto") won’t load the classification head. I’ll update the docs to useAutoImageProcessorandAutoModelForImageClassification` so users can run inference directly with the HF model.

Since the local app.py doesn’t depend on transformers, this is just an informational fix, but I agree it’s worth cleaning up. I can push the doc change here before merge, or handle it in a quick follow-up PR whichever you prefer.

Appreciate the detailed feedback and the merge readiness check!

@tkarim45

tkarim45 commented May 6, 2026

Copy link
Copy Markdown
Owner

Thanks @ARUNAGIRINATHAN-K! Let's keep it as a single PR — please push the README snippet fix to this branch and I'll merge as soon as CI goes green again. No rush.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants