I have a list (see LIST) that I want to send to a dictionary.
But I do not want to send all the data. Just some values (see SOME VALUES/FEATURES) which happen to repeat many times. For example, the word "Model: xxx" appears like 7 times. "xxx" is the name of the model and it will change.
So far I can only put in the dictionary the last values of the list. How can I put all the values from the list into the dictionary?
SOME VALUES:
Labels: xxxx
Model: xxxx
Image: xxxx
Inference: xxxx
Score: xxxx
TPU_temp(°C): xxxx
Time(ms): xxx ---There are 2 of these, I do not know if it is possible to extract ONLY the second one. But if not, no problem. Extracting both will be fine.--
THIS IS THE CODE - ATTEMPT 1
#this is to match tha values/features that I want to extract
regex = re.compile(r'(\w+)\((.+)\):\s(.*)|(\w+:)\s(.*)')
match_regex = list(filter(regex.match, output))
match = [line.rstrip('\n') for line in match_regex]
features_wanted='ModelImageTime(ms)InferenceScoreTPU_temp(°C)'
#Removing whitespaces and splitting data into "key:value"
#Sending the values/features into a dictionary
dct={i.replace(' ','').split(':')[0]:i.replace(' ','').split(':')[1] for i in match if i.replace(' ','').split(':')[0] in features_wanted}
print(dct, '\n')
THIS IS THE DICTIONARY THAT I GET WITH MY CODE - ATTEMPT 1
Only the last value of the list appears.
THIS IS THE CODE - ATTEMPT 2
regex = re.compile(r'(\w+)\((.+)\):\s(.*)|(\w+:)\s(.*)')
match_regex = list(filter(regex.match, data))
match = [line.rstrip('\n') for line in match_regex]
dixie=dict(list(enumerate(match)))
THIS IS THE DICTIONARY THAT I GET WITH MY CODE - ATTEMPT 2
Here I am sending all the list into the dictionary. But I haven't removed whitespaces neither divided data into "key:value"
LIST (original list looks like this)
THIS IS THE LIST (so you can test)
[
"labels: imagenet_labels.txt ",
"Model: efficientnet-edgetpu-S_quant_edgetpu.tflite ",
"Image: insect.jpg ",
"Time(ms): 23.1",
"Time(ms): 5.7",
"Inference: corkscrew, bottle screw",
"Score: 0.03125 ",
"TPU_temp(°C): 57.05",
"labels: imagenet_labels.txt ",
"Model: efficientnet-edgetpu-M_quant_edgetpu.tflite ",
"Image: insect.jpg ",
"Time(ms): 29.3",
"Time(ms): 10.8",
"Inference: dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk",
"Score: 0.09375 ",
"TPU_temp(°C): 56.8",
"labels: imagenet_labels.txt ",
"Model: efficientnet-edgetpu-L_quant_edgetpu.tflite ",
"Image: insect.jpg ",
"Time(ms): 45.6",
"Time(ms): 31.0",
"Inference: pick, plectrum, plectron",
"Score: 0.09766 ",
"TPU_temp(°C): 57.55",
"labels: imagenet_labels.txt ",
"Model: inception_v3_299_quant_edgetpu.tflite ",
"Image: insect.jpg ",
"Time(ms): 68.8",
"Time(ms): 51.3",
"Inference: ringlet, ringlet butterfly",
"Score: 0.48047 ",
"TPU_temp(°C): 57.3",
"labels: imagenet_labels.txt ",
"Model: inception_v4_299_quant_edgetpu.tflite ",
"Image: insect.jpg ",
"Time(ms): 121.8",
"Time(ms): 101.2",
"Inference: admiral",
"Score: 0.59375 ",
"TPU_temp(°C): 57.05",
"labels: imagenet_labels.txt ",
"Model: inception_v2_224_quant_edgetpu.tflite ",
"Image: insect.jpg ",
"Time(ms): 34.3",
"Time(ms): 16.6",
"Inference: lycaenid, lycaenid butterfly",
"Score: 0.41406 ",
"TPU_temp(°C): 57.3",
"labels: imagenet_labels.txt ",
"Model: mobilenet_v2_1.0_224_quant_edgetpu.tflite ",
"Image: insect.jpg ",
"Time(ms): 14.4",
"Time(ms): 3.3",
"Inference: leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea",
"Score: 0.36328 ",
"TPU_temp(°C): 57.3",
"labels: imagenet_labels.txt ",
"Model: mobilenet_v1_1.0_224_quant_edgetpu.tflite ",
"Image: insect.jpg ",
"Time(ms): 14.5",
"Time(ms): 3.0",
"Inference: bow tie, bow-tie, bowtie",
"Score: 0.33984 ",
"TPU_temp(°C): 57.3",
"labels: imagenet_labels.txt ",
"Model: inception_v1_224_quant_edgetpu.tflite ",
"Image: insect.jpg ",
"Time(ms): 21.2",
"Time(ms): 3.6",
"Inference: pick, plectrum, plectron",
"Score: 0.17578 ",
"TPU_temp(°C): 57.3",
]