sergioska commited on
Commit
0911304
·
1 Parent(s): 5f53f40

fix load image

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -41,22 +41,18 @@ texts = st.text_input('apple, eggs')
41
  image = ''
42
  if uploaded_image_zero_file is not None:
43
  with NamedTemporaryFile() as temp:
44
- temp.write(uploaded_image_zero_file.getvalue())
45
- temp.seek(0)
46
  image = Image.open(uploaded_image_zero_file)
47
  outputImage = np.array(image)
48
  st.image(outputImage)
49
-
50
- if st.button('check tags'):
51
- inputs = processor(text=texts, images=image, return_tensors="pt")
52
- outputs = model(**inputs)
53
- target_sizes = torch.Tensor([image.size[::-1]])
54
- results = processor.post_process_object_detection(outputs=outputs, threshold=0.1, target_sizes=target_sizes)
55
- i = 0 # Retrieve predictions for the first image for the corresponding text queries
56
- text = texts[i]
57
- boxes, scores, labels = results[i]["boxes"], results[i]["scores"], results[i]["labels"]
58
- st.write(results)
59
- # Print detected objects and rescaled box coordinates
60
- for box, score, label in zip(boxes, scores, labels):
61
- box = [round(i, 2) for i in box.tolist()]
62
- print(f"Detected {text[label]} with confidence {round(score.item(), 3)} at location {box}")
 
41
  image = ''
42
  if uploaded_image_zero_file is not None:
43
  with NamedTemporaryFile() as temp:
 
 
44
  image = Image.open(uploaded_image_zero_file)
45
  outputImage = np.array(image)
46
  st.image(outputImage)
47
+ inputs = processor(text=texts, images=image, return_tensors="pt")
48
+ outputs = model(**inputs)
49
+ target_sizes = torch.Tensor([image.size[::-1]])
50
+ results = processor.post_process_object_detection(outputs=outputs, threshold=0.1, target_sizes=target_sizes)
51
+ i = 0 # Retrieve predictions for the first image for the corresponding text queries
52
+ text = texts[i]
53
+ boxes, scores, labels = results[i]["boxes"], results[i]["scores"], results[i]["labels"]
54
+ st.write(results)
55
+ # Print detected objects and rescaled box coordinates
56
+ for box, score, label in zip(boxes, scores, labels):
57
+ box = [round(i, 2) for i in box.tolist()]
58
+ print(f"Detected {text[label]} with confidence {round(score.item(), 3)} at location {box}")