mattb512 commited on
Commit
43353bb
1 Parent(s): 94c65ad

print processing time

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -5,6 +5,7 @@ from torch import nn
5
  import gradio as gr
6
  import os
7
  import torch
 
8
 
9
  feature_extractor = SegformerFeatureExtractor.from_pretrained("nvidia/segformer-b5-finetuned-cityscapes-1024-1024")
10
  model = SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b5-finetuned-cityscapes-1024-1024")
@@ -50,9 +51,11 @@ def annotation(image:ImageDraw, color_seg:np.array):
50
  draw.rectangle([(x, y), (x + step_size, y + step_size)], outline="white", width=3)
51
 
52
  def call(image): #nparray
 
53
 
54
  print(f"Is CUDA available: {torch.cuda.is_available()}")
55
- print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
 
56
 
57
  resized = Image.fromarray(image).resize((1024,1024))
58
  resized_image = np.array(resized)
@@ -95,6 +98,9 @@ def call(image): #nparray
95
  out_im_file = Image.fromarray(img)
96
  annotation(out_im_file, color_seg)
97
 
 
 
 
98
  return out_im_file
99
 
100
  # original_image = Image.open("./examples/1.jpg")
 
5
  import gradio as gr
6
  import os
7
  import torch
8
+ import time
9
 
10
  feature_extractor = SegformerFeatureExtractor.from_pretrained("nvidia/segformer-b5-finetuned-cityscapes-1024-1024")
11
  model = SegformerForSemanticSegmentation.from_pretrained("nvidia/segformer-b5-finetuned-cityscapes-1024-1024")
 
51
  draw.rectangle([(x, y), (x + step_size, y + step_size)], outline="white", width=3)
52
 
53
  def call(image): #nparray
54
+ start = time.time()
55
 
56
  print(f"Is CUDA available: {torch.cuda.is_available()}")
57
+ if (torch.cuda.is_available()):
58
+ print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
59
 
60
  resized = Image.fromarray(image).resize((1024,1024))
61
  resized_image = np.array(resized)
 
98
  out_im_file = Image.fromarray(img)
99
  annotation(out_im_file, color_seg)
100
 
101
+ end = time.time()
102
+ print(f"processing time: {(end - start):.2f} s")
103
+
104
  return out_im_file
105
 
106
  # original_image = Image.open("./examples/1.jpg")