cdnuts commited on
Commit
cb636fa
1 Parent(s): 58355c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -257,23 +257,22 @@ def process_images(images, threshold):
257
 
258
  with torch.no_grad():
259
  for batch, filenames in dataloader:
260
-
261
  batch = batch.to(device)
262
- with torch.no_grad():
263
- probabilities = model(batch)
264
- for i, prob in enumerate(probabilities):
265
- prob = prob[0]
266
- indices = torch.where(prob > threshold)[0]
267
- values = prob[indices]
268
-
269
- temp = []
270
- tag_score = dict()
271
- for j in range(indices.size(0)):
272
- temp.append([allowed_tags[indices[j]], values[j].item()])
273
- tag_score[allowed_tags[indices[j]]] = values[j].item()
274
-
275
- tags = ", ".join([t[0] for t in temp])
276
- all_results.append((filenames[i], tags, tag_score))
277
 
278
  return all_results
279
 
 
257
 
258
  with torch.no_grad():
259
  for batch, filenames in dataloader:
 
260
  batch = batch.to(device)
261
+ probabilities = model(batch)
262
+ for i, prob in enumerate(probabilities):
263
+ indices = torch.where(prob > threshold)[0]
264
+ values = prob[indices]
265
+
266
+ temp = []
267
+ tag_score = dict()
268
+ for j in range(indices.size(0)):
269
+ tag = allowed_tags[indices[j]]
270
+ score = values[j].item()
271
+ temp.append([tag, score])
272
+ tag_score[tag] = score
273
+
274
+ tags = ", ".join([t[0] for t in temp])
275
+ all_results.append((filenames[i], tags, tag_score))
276
 
277
  return all_results
278