rld / models /rice_model.py
zynt31's picture
Upload 10 files
6b36551 verified
raw
history blame contribute delete
987 Bytes
import torch
import torch.nn as nn
import torch.nn.functional as F
class RiceDiseaseCNN(nn.Module):
def __init__(self, num_classes=4): # 4 classes: Tungro, BrownSpot, Blast, BacterialBlight
super(RiceDiseaseCNN, self).__init__()
self.conv1 = nn.Conv2d(3, 16, kernel_size=3, padding=1) # Input: RGB images
self.conv2 = nn.Conv2d(16, 32, kernel_size=3, padding=1)
self.conv3 = nn.Conv2d(32, 64, kernel_size=3, padding=1)
self.pool = nn.MaxPool2d(kernel_size=2, stride=2)
self.fc1 = nn.Linear(64 * 28 * 28, 128) # Assuming 224x224 input
self.fc2 = nn.Linear(128, num_classes)
self.dropout = nn.Dropout(0.5)
def forward(self, x):
x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
x = self.pool(F.relu(self.conv3(x)))
x = x.view(-1, 64 * 28 * 28) # Flatten
x = F.relu(self.fc1(x))
x = self.dropout(x)
x = self.fc2(x)
return x