Reputation: 21
I want to store each detection value and combine it into an array to save it to excel. I want to apped sa_mask to add all detection values to save_mask variable, but I tried apped and got only the last detected value. It doesn't store all values. enter image description here
if FLAGS.count:
# count objects found
counted_classes = count_objects(pred_bbox, by_class = True)
# loop through dict and print
sa_counted = np.array(counted_classes)
print(sa_counted)
for key, value in counted_classes.items():
print("Number of {}s: {}".format(key, value))
sa_mask = ("{} {}".format(key, value))
save_mask = []
save_mask.apped(sa_mask)
Upvotes: 2
Views: 729
Reputation: 93
You're simply not storing the values and adding them together, so each time the loop is entered, it just keeps overwriting the previous results...
I'll try simplifying this as much as possible :
# DATA
sa_counted1 = {"Surgical": 5, "KN95": 2, "Cloth": 1}
sa_counted2 = {"Surgical": 10, "KN95": 7, "Cloth": 3}
sa_counted3 = {"Surgical": 15, "KN95": 12, "Cloth": 5}
# WHERE THE RESULT WILL BE STORED
counted_classes = {}
# ADDING THE VALUES OF THE DICTIONARIES TOGETHER
for sa_counted in [sa_counted1, sa_counted2, sa_counted3]:
for key, value in sa_counted.items():
if key in counted_classes:
counted_classes[key] += value
else:
counted_classes[key] = value
# PRINT THE RESULT
for key, value in counted_classes.items():
print("Number of {}s: {}".format(key, value))
I hope this was helpful.
Upvotes: 1