Spaces:
Runtime error
Runtime error
Update app.py
Browse files4 unmodified lines56789101112131415161718192021222324254 unmodified linesfrom PIL import Imageimport gradio as grfrom huggingface_hub import hf_hub_download# Configure devicedevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')transform = torchvision.transforms.Compose([torchvision.transforms.Resize((224, 224)),torchvision.transforms.ToTensor(),torchvision.transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.225, 0.225, 0.225])])REPO_ID = "Raaniel/model-smoke"MODEL_FILE_NAME = "model_smoke.pt"checkpoint_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILE_NAME)model = torch.jit.load(checkpoint_path)model = model.to(device)classes = ["chmury", 'inne', "dym"]4 unmodified lines5678910111213141516171819202122232425262728293031323334353637383940414 unmodified linesfrom PIL import Imageimport gradio as grfrom huggingface_hub import hf_hub_downloadimport torch.nn as nnimport timmREPO_ID = "Raaniel/model-smoke"MODEL_FILE_NAME = "model_smoke.pt"USE_CUDA = torch.cuda.is_available()num_classes = 3# Download the modelcheckpoint_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILE_NAME)# Load the checkpointstate = torch.load(checkpoint_path, map_location=torch.device('cuda' if USE_CUDA else 'cpu'))# Create the model and modify itmodel = timm.create_model('mobilenetv3_small_050', pretrained=True)num_features = model.classifier.in_features# Additional linear and dropout layersmodel.classifier = nn.Sequential(nn.Linear(num_features, 256), # Additional linear layernn.ReLU(inplace=True),nn.Dropout(0.5),nn.Linear(256, num_classes) # Final classification layer)# Load the model weightsmodel.load_state_dict(state['weights'])# Move model to the appropriate devicedevice = torch.device('cuda' if USE_CUDA else 'cpu')model = model.to(device)classes = ["chmury", 'inne', "dym"]
app.py+26-10