This is based on the ResNet18 model and is used to determine whether an image is anime or real life photography. The accuracy has limitations. To use the model, you can refer to the following code: import torch import torch.nn as nn import torch.nn.functional as F from torchvision import transforms from PIL import Image import os from torchvision import models Set up device configuration to use GPU if available device = torch.device("cuda" if torch.cuda.is available() else "cpu") Load pre trained ResNet18 model and modify the final layer for 2 class classification model = models.resnet18() model.fc = nn.Linear(model.fc.in features, 2) model.load state dict(torch.load('resnet18 anime real.pth', map location=device)) model.to(device) model.eval() Image preprocessing pipeline matching the training setup (uses ImageNet mean/std) transform = transforms.Compose([ transforms.Resize((224, 224)), Input size for ResNet transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) ]) Define inference function to classify images def predict image(img path): image = Image.open(img path).convert('RGB') image = transform(image).unsqueeze(0).to(device) Add batc…
We use cookies for essential functionality and analytics. You can accept or reject analytics cookies.Cookie policy