VatsalPatel18 commited on
Commit
3d8f88a
1 Parent(s): 2066c38

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +4 -3
main.py CHANGED
@@ -8,14 +8,15 @@ def load_and_preprocess_image(image_path, clip_processor_path):
8
  clip_processor = CLIPImageProcessor.from_pretrained(clip_processor_path)
9
  image = Image.open(image_path).convert("RGB")
10
  inputs = clip_processor(images=[image], return_tensors="pt")
11
- image_tensor = inputs['pixel_values']
12
  return image_tensor
13
 
14
  def genomic_plip_predictions(image_tensor, model_path):
15
- gmodel = GenomicPLIPModel.from_pretrained(model_path)
 
16
  gmodel.eval()
17
  with torch.no_grad():
18
- pred_data = gmodel(image_tensor)
19
  return pred_data
20
 
21
  def classify_tiles(pred_data, model_path):
 
8
  clip_processor = CLIPImageProcessor.from_pretrained(clip_processor_path)
9
  image = Image.open(image_path).convert("RGB")
10
  inputs = clip_processor(images=[image], return_tensors="pt")
11
+ image_tensor = inputs['pixel_values'].to('cuda' if torch.cuda.is_available() else 'cpu')
12
  return image_tensor
13
 
14
  def genomic_plip_predictions(image_tensor, model_path):
15
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
16
+ gmodel = GenomicPLIPModel.from_pretrained(model_path).to(device)
17
  gmodel.eval()
18
  with torch.no_grad():
19
+ pred_data = gmodel(image_tensor.to(device))
20
  return pred_data
21
 
22
  def classify_tiles(pred_data, model_path):