@@ -105,10 +105,10 @@ class PASCALDataFetch(DatasetImageFetch):
105105 colors = []
106106 i = 0
107107
108- def __init__ (self , img_dir , segm_dir , names_file , segm_cls_colors_file , preproc ):
108+ def __init__ (self , img_dir , segm_dir , names_file , segm_cls_colors , preproc ):
109109 self .img_dir = img_dir
110110 self .segm_dir = segm_dir
111- self .colors = self .read_colors (segm_cls_colors_file )
111+ self .colors = self .read_colors (segm_cls_colors )
112112 self .data_prepoc = preproc
113113 self .i = 0
114114
@@ -117,12 +117,10 @@ def __init__(self, img_dir, segm_dir, names_file, segm_cls_colors_file, preproc)
117117 self .names .append (l .rstrip ())
118118
119119 @staticmethod
120- def read_colors (img_classes_file ):
120+ def read_colors (colors ):
121121 result = []
122- with open (img_classes_file ) as f :
123- for l in f .readlines ():
124- color = list (map (int , l .strip ().split (" " )[1 :]))
125- result .append (DatasetImageFetch .pix_to_c (color ))
122+ for color in colors :
123+ result .append (DatasetImageFetch .pix_to_c (color ))
126124 return result
127125
128126 def __iter__ (self ):
@@ -205,14 +203,37 @@ def process(self, frameworks, data_fetcher):
205203 log_str = frameworks [0 ].get_name () + " vs " + frameworks [i ].get_name () + ':'
206204 print ('Final l1 diff' , log_str , blobs_l1_diff [i ] / blobs_l1_diff_count [i ], file = self .log )
207205
206+ # PASCAL VOC 2012 classes colors
207+ colors_pascal_voc_2012 = [
208+ [0 , 0 , 0 ],
209+ [128 , 0 , 0 ],
210+ [0 , 128 , 0 ],
211+ [128 , 128 , 0 ],
212+ [0 , 0 , 128 ],
213+ [128 , 0 , 128 ],
214+ [0 , 128 , 128 ],
215+ [128 , 128 , 128 ],
216+ [64 , 0 , 0 ],
217+ [192 , 0 , 0 ],
218+ [64 , 128 , 0 ],
219+ [192 , 128 , 0 ],
220+ [64 , 0 , 128 ],
221+ [192 , 0 , 128 ],
222+ [64 , 128 , 128 ],
223+ [192 , 128 , 128 ],
224+ [0 , 64 , 0 ],
225+ [128 , 64 , 0 ],
226+ [0 , 192 , 0 ],
227+ [128 , 192 , 0 ],
228+ [0 , 64 , 128 ],
229+ ]
230+
208231if __name__ == "__main__" :
209232 parser = argparse .ArgumentParser ()
210233 parser .add_argument ("--imgs_dir" , help = "path to PASCAL VOC 2012 images dir, data/VOC2012/JPEGImages" )
211234 parser .add_argument ("--segm_dir" , help = "path to PASCAL VOC 2012 segmentation dir, data/VOC2012/SegmentationClass/" )
212235 parser .add_argument ("--val_names" , help = "path to file with validation set image names, download it here: "
213236 "https://github.com/shelhamer/fcn.berkeleyvision.org/blob/master/data/pascal/seg11valid.txt" )
214- parser .add_argument ("--cls_file" , help = "path to file with colors for classes, download it here: "
215- "https://raw.githubusercontent.com/opencv/opencv/3.4.1/samples/data/dnn/pascal-classes.txt" )
216237 parser .add_argument ("--prototxt" , help = "path to caffe prototxt, download it here: "
217238 "https://github.com/opencv/opencv/blob/5.x/samples/data/dnn/fcn8s-heavy-pascal.prototxt" )
218239 parser .add_argument ("--caffemodel" , help = "path to caffemodel file, download it here: "
@@ -225,7 +246,7 @@ def process(self, frameworks, data_fetcher):
225246 args = parser .parse_args ()
226247
227248 prep = MeanChannelsPreproc ()
228- df = PASCALDataFetch (args .imgs_dir , args .segm_dir , args .val_names , args . cls_file , prep )
249+ df = PASCALDataFetch (args .imgs_dir , args .segm_dir , args .val_names , colors_pascal_voc_2012 , prep )
229250
230251 fw = [CaffeModel (args .prototxt , args .caffemodel , args .in_blob , args .out_blob , True ),
231252 DNNOnnxModel (args .onnxmodel , args .in_blob , args .out_blob )]
0 commit comments