Open Usernamezhx opened 3 years ago
thanks for you work. I test pair image by the model:imagenet_64bit_0.8734_resnet50.pkl. and get the hamming distance:0 This is my test code:
class CSQ(object): def __init__(self): self.model_path = 'checkpoint/imagenet_64bit_0.8734_resnet50.pkl' self.device = "cuda" if torch.cuda.is_available() else "cpu" self.transform = prep.image_test(resize_size=255, crop_size=224) self.load_model() def load_model(self, ): self.model = torch.load(self.model_path) self.model = self.model.module self.model.to(device=self.device) self.model.eval() def forward(self, img_path): tensor_img = self.transform(Image.open(img_path).convert('RGB')).unsqueeze(0).to(self.device) with torch.no_grad(): out = self.model(tensor_img) hash_code = out.cpu().numpy() hash_code[hash_code < 0] = -1 hash_code[hash_code >= 0] = 1 code_list = ''.join(['1' if item == 1.0 else '0' for item in hash_code[0].tolist()]) return code_list
thanks for you work. I test pair image by the model:imagenet_64bit_0.8734_resnet50.pkl. and get the hamming distance:0 This is my test code: