Repository: open-mmlab/mmdetection

Issue:
./tools/analysis_tools/analyze_logs.py plot_curve  IndexError: list index out of range
`(openmmlab) lbc@prust-System-3:~/mmdetection-master$ python3.8 ./tools/analysis_tools/analyze_logs.py plot_curve ./work_dirs/deformable_detr_twostage_refine_r50_16x2_50e_coco/20211119_170702.log.json --keys bbox_mAP 
plot curve of ./work_dirs/deformable_detr_twostage_refine_r50_16x2_50e_coco/20211119_170702.log.json, metric is bbox_mAP
Traceback (most recent call last):
  File "./tools/analysis_tools/analyze_logs.py", line 180, in <module>
    main()
  File "./tools/analysis_tools/analyze_logs.py", line 176, in main
    eval(args.task)(log_dicts, args)
  File "./tools/analysis_tools/analyze_logs.py", line 53, in plot_curve
    if metric not in log_dict[epochs[0]]:
IndexError: list index out of range
`


Discussion:

Resolving patch:
diff --git a/tools/analysis_tools/analyze_logs.py b/tools/analysis_tools/analyze_logs.py
old mode 100644
new mode 100755
--- a/tools/analysis_tools/analyze_logs.py
+++ b/tools/analysis_tools/analyze_logs.py
@@ -17,6 +17,10 @@ def cal_train_time(log_dicts, args):
                 all_times.append(log_dict[epoch]['time'])
             else:
                 all_times.append(log_dict[epoch]['time'][1:])
+        if not all_times:
+            raise KeyError(
+                'Please reduce the log interval in the config so that'
+                'interval is less than iterations of one epoch.')
         all_times = np.array(all_times)
         epoch_ave_time = all_times.mean(-1)
         slowest_epoch = epoch_ave_time.argmax()
@@ -50,12 +54,21 @@ def plot_curve(log_dicts, args):
         epochs = list(log_dict.keys())
         for j, metric in enumerate(metrics):
             print(f'plot curve of {args.json_logs[i]}, metric is {metric}')
-            if metric not in log_dict[epochs[0]]:
+            if metric not in log_dict[epochs[int(args.start_epoch) - 1]]:
+                if 'mAP' in metric:
+                    raise KeyError(
+                        f'{args.json_logs[i]} does not contain metric '
+                        f'{metric}. Please check if "--no-validate" is '
+                        'specified when you trained the model.')
                 raise KeyError(
-                    f'{args.json_logs[i]} does not contain metric {metric}')
+                    f'{args.json_logs[i]} does not contain metric {metric}. '
+                    'Please reduce the log interval in the config so that '
+                    'interval is less than iterations of one epoch.')
 
             if 'mAP' in metric:
-                xs = np.arange(1, max(epochs) + 1)
+                xs = np.arange(
+                    int(args.start_epoch),
+                    max(epochs) + 1, int(args.eval_interval))
                 ys = []
                 for epoch in epochs:
                     ys += log_dict[epoch][metric]
@@ -104,6 +117,16 @@ def add_plot_parser(subparsers):
         nargs='+',
         default=['bbox_mAP'],
         help='the metric that you want to plot')
+    parser_plt.add_argument(
+        '--start-epoch',
+        type=str,
+        default='1',
+        help='the epoch that you want to start')
+    parser_plt.add_argument(
+        '--eval-interval',
+        type=str,
+        default='1',
+        help='the eval interval when training')
     parser_plt.add_argument('--title', type=str, help='title of figure')
     parser_plt.add_argument(
         '--legend',


Test patch: