Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

set threshold resnet18 pytorch

from PIL import Image
import torch
from torchvision import transforms
input_image = Image.open("img/danbooru_resnet1.png") # load an image of your choice
preprocess = transforms.Compose([
    transforms.Resize(360),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.7137, 0.6628, 0.6519], std=[0.2970, 0.3017, 0.2979]),
])
input_tensor = preprocess(input_image)
input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model

if torch.cuda.is_available():
    input_batch = input_batch.to('cuda')
    model.to('cuda')

with torch.no_grad():
    output = model(input_batch)

# The output has unnormalized scores. To get probabilities, you can run a sigmoid on it.
probs = torch.sigmoid(output[0]) # Tensor of shape 6000, with confidence scores over Danbooru's top 6000 tags

# Second part of the code 
# to set a threshold value and to use it 
tmp = probs[probs > thresh]
inds = probs.argsort(descending=True)
Comment

PREVIOUS NEXT
Code Example
Python :: import math print(math.log(1024,2)) 
Python :: build spacy custom ner model stackoverflow 
Python :: python is not writing whole line 
Python :: pandas filter and change value 
Python :: google translate python 
Python :: write a program to check whether a character is vowel or consonant in python 
Python :: pandas series select first value 
Python :: how to change python version on linux 
Python :: sort a pandas dataframe based on date and time 
Python :: how to convert index to column in pandas 
Python :: python how to create attribute of class while iterating a list 
Python :: python temp directory 
Python :: rotation points space python 
Python :: pytube search feature 
Python :: raatatatatatatatatatatatatatatatatatatatatatatatatatatattatana 
Python :: python execute bat file 
Python :: download stopwords nltk 
Python :: np.sort descending 
Python :: how to type a dict in python 
Python :: convert string to operator python 
Python :: python how to check which int var is the greatest 
Python :: tkinter progresse bar color 
Python :: python yyyymmdd 
Python :: python opencv create new image 
Python :: show image with ratio opencv python 
Python :: how to set the size of a gui in python 
Python :: delay time python 
Python :: numpy.datetime64 to datetime 
Python :: python bold text 
Python :: python read file in string list 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =