I'm new to python. When I was studying the code for yolov3, I had a headache because lambda, map, and list were written on one line. I would like to write it as a memo for myself.
It is the code around 85 lines in yolo.py of keras-yolov3.
1_yolo_code_around_85.py
self.colors = list(map(lambda x: colorsys.hsv_to_rgb(*x), hsv_tuples))
Difficult elements and explanations of them ・ (* X): Variadic argument ・ Lamb: Anonymous function ・ Map: Built-in function ・ List: List
hsv_to_rgb requires 3 arguments corresponding to hsv. Therefore, it can be changed as follows.
2_yolo_code_around_85.py
self.colors = list(map(lambda x: colorsys.hsv_to_rgb(x[0],x[1],x[2]), hsv_tuples))
It is easy to imagine if the list x is made as above. Define a function using list x by lambda Assign the value of hsv_tuples to the function. Use map to do the same for all elements List.
Recommended Posts