Page MenuHomePhabricator
Paste P58864

logo-detection: prototype for JSON response
ActivePublic

Authored by kevinbazira on Mar 21 2024, 11:54 AM.
Referenced Files
F42943840: logo-detection: prototype for JSON response
Mar 21 2024, 11:54 AM
Subscribers
None
CODE ADDED TO PROTOTYPE:
```
import json
response = []
# Iterate through the test set and make predictions
for images, labels in test_set.take(1):
for i in range(len(images)):
filename = test_set.file_paths[i].split('/')[-1]
predictions = model(keras.ops.expand_dims(images[i], 0))[0]
rounded_predictions = np.around(predictions, decimals=2).astype(float)
prediction = {
'filename': filename,
'target': target,
'prediction': {
'logo': rounded_predictions[1],
'out_of_domain': rounded_predictions[0]
}
}
response.append(prediction)
# Output response in JSON format
print(json.dumps(response, indent=4))
```
JSON RESPONSE RETURNED:
```
[
{
"filename": "Cambia_logo.png",
"target": "logo",
"prediction": {
"logo": 1.0,
"out_of_domain": 0.0
}
},
{
"filename": "Blooming_bush_(14248894271).jpg",
"target": "logo",
"prediction": {
"logo": 0.0,
"out_of_domain": 1.0
}
},
{
"filename": "Evex_logo_english_square.png",
"target": "logo",
"prediction": {
"logo": 0.05000000074505806,
"out_of_domain": 0.949999988079071
}
},
{
"filename": "Doberschuetz_Kirche-01.jpg",
"target": "logo",
"prediction": {
"logo": 1.0,
"out_of_domain": 0.0
}
},
{
"filename": "CFC_logo1_(002).jpg",
"target": "logo",
"prediction": {
"logo": 0.009999999776482582,
"out_of_domain": 0.9900000095367432
}
},
{
"filename": "BackupVault_Logo_2019.png",
"target": "logo",
"prediction": {
"logo": 1.0,
"out_of_domain": 0.0
}
},
{
"filename": "Elizabeth_Drive_-_border_of_Edensor_Park_and_Bonnyrigg_Heights_in_New_South_Wales_62.jpg",
"target": "logo",
"prediction": {
"logo": 0.0,
"out_of_domain": 1.0
}
},
{
"filename": "12_rue_de_Cond\u00e9_-_detail.jpg",
"target": "logo",
"prediction": {
"logo": 1.0,
"out_of_domain": 0.0
}
},
{
"filename": "91038-Auvers-Saint-Georges-g\u00e9ologie.png",
"target": "logo",
"prediction": {
"logo": 0.0,
"out_of_domain": 1.0
}
},
{
"filename": "Abv.png",
"target": "logo",
"prediction": {
"logo": 1.0,
"out_of_domain": 0.0
}
}
]
```

Event Timeline

The logo detection prototype currently returns predictions in a plotted grid as shown in T358676#9629389. The code above was added to the prototype and it now returns the prediction in JSON format with keys specified in T358676#9637065.