-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
36 lines (28 loc) · 981 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
import os
import random
import json
import time
API_URL = 'http://localhost:8000/'
# Choisir une image au hasard et l'envoyer à l'API pour prédiction
def random_image_choice():
os.chdir('data/Test')
random_folder = random.choice(os.listdir())
os.chdir(random_folder)
random_image = random.choice(os.listdir())
return random_folder, random_image
def send_image_to_api(folder, image):
with open(image, 'rb') as f:
files = {'file': f}
response = requests.post(API_URL + 'predict', files=files)
print(response.json())
print(f"Image: {image} - Prediction: {response.json()['predicted_class']} - True label: {folder}")
if __name__ == '__main__':
while True:
folder, image = random_image_choice()
try :
send_image_to_api(folder, image)
except:
print("Error")
time.sleep(random.uniform(0.1, 0.5))
os.chdir('../../..')