Ariamehr commited on
Commit
6632d28
·
verified ·
1 Parent(s): 7ada48a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -11,11 +11,11 @@ model.eval()
11
  def predict(image):
12
  try:
13
  print("Predict function called")
14
-
15
- # تعیین اندازه ورودی مدل
16
- target_size = (512, 512) # این اندازه را می‌توانید تغییر دهید
17
  image = image.resize(target_size)
18
-
19
  # پیش‌پردازش تصویر
20
  image = image.convert("RGB")
21
  input_tensor = np.array(image)
@@ -23,23 +23,22 @@ def predict(image):
23
  input_tensor = input_tensor[np.newaxis, :] # افزودن بعد batch
24
  input_tensor = input_tensor / 255.0 # نرمال‌سازی
25
  input_tensor = torch.from_numpy(input_tensor).float()
26
-
27
  print(f"Input tensor shape: {input_tensor.shape}")
28
 
29
  # اجرای مدل
30
  with torch.no_grad():
31
  output = model(input_tensor)
32
-
33
  print(f"Output tensor shape: {output.shape}")
34
-
35
  # پس‌پردازش خروجی
36
  output_image = output.squeeze().cpu().numpy()
37
  output_image = output_image.transpose(1, 2, 0) # تبدیل از CHW به HWC
38
  output_image = (output_image * 255).astype(np.uint8)
39
  output_image = Image.fromarray(output_image)
40
-
41
  print("Output image generated successfully")
42
-
43
  return output_image
44
 
45
  except Exception as e:
 
11
  def predict(image):
12
  try:
13
  print("Predict function called")
14
+
15
+ # تغییر اندازه تصویر به اندازه‌ای که احتمالاً مدل نیاز دارد
16
+ target_size = (1024, 1024) # این اندازه را به اندازه‌ای که مدل نیاز دارد تغییر دهید
17
  image = image.resize(target_size)
18
+
19
  # پیش‌پردازش تصویر
20
  image = image.convert("RGB")
21
  input_tensor = np.array(image)
 
23
  input_tensor = input_tensor[np.newaxis, :] # افزودن بعد batch
24
  input_tensor = input_tensor / 255.0 # نرمال‌سازی
25
  input_tensor = torch.from_numpy(input_tensor).float()
26
+
27
  print(f"Input tensor shape: {input_tensor.shape}")
28
 
29
  # اجرای مدل
30
  with torch.no_grad():
31
  output = model(input_tensor)
32
+
33
  print(f"Output tensor shape: {output.shape}")
34
+
35
  # پس‌پردازش خروجی
36
  output_image = output.squeeze().cpu().numpy()
37
  output_image = output_image.transpose(1, 2, 0) # تبدیل از CHW به HWC
38
  output_image = (output_image * 255).astype(np.uint8)
39
  output_image = Image.fromarray(output_image)
40
+
41
  print("Output image generated successfully")
 
42
  return output_image
43
 
44
  except Exception as e: