Update README.md
Browse files42 unmodified lines43444546474849505152535455565724 unmodified lines8283848586878842 unmodified linesdevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")# Load model classclass_path = hf_hub_download(repo_id="PerceptCLIP/PerceptCLIP_Emotions", filename="modeling.py")spec = importlib.util.spec_from_file_location("clip_lora_model", class_path)clip_lora_model = importlib.util.module_from_spec(spec)spec.loader.exec_module(clip_lora_model)# Load pretrained modelmodel_path = hf_hub_download(repo_id="PerceptCLIP/PerceptCLIP_Emotions", filename="perceptCLIP_Emotions.pth")model = torch.load(model_path).to(device).eval()# Emotion label mappingidx2label = {24 unmodified lines# Run inferencewith torch.no_grad():outputs = model(image)_, predicted = outputs.max(1) # Get the class index# Get emotion labelpredicted_emotion = idx2label[predicted.item()]42 unmodified lines434445464748495051525354555657585960616224 unmodified lines8788899091929342 unmodified linesdevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")# Load the model class definition dynamicallyclass_path = hf_hub_download(repo_id="PerceptCLIP/PerceptCLIP_Emotions", filename="modeling.py")spec = importlib.util.spec_from_file_location("modeling", class_path)modeling = importlib.util.module_from_spec(spec)spec.loader.exec_module(modeling)# initialize a modelModelClass = modeling.clip_lora_modelmodel = ModelClass().to(device)# Load pretrained modelmodel_path = hf_hub_download(repo_id="PerceptCLIP/PerceptCLIP_Emotions", filename="perceptCLIP_Emotions.pth")model.load_state_dict(torch.load(model_path, map_location=device))model.eval()# Emotion label mappingidx2label = {24 unmodified lines# Run inferencewith torch.no_grad():outputs = model(image)_, predicted = outputs.max(1)# Get emotion labelpredicted_emotion = idx2label[predicted.item()]
README.md+11-6