Skip to content

Commit d6ec47c

Browse files
[Fix] fix some problems in chartmimic
1 parent 977459d commit d6ec47c

File tree

8 files changed

+88
-34
lines changed

8 files changed

+88
-34
lines changed

vlmeval/dataset/chartmimic.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,27 +519,55 @@ def build_prompt(self, line):
519519

520520
return msgs
521521

522+
522523
def evaluate(self, eval_file, **judge_kwargs):
523524
def judge_one_item_success(item):
524525
return item["high_level"]["resp"] not in [FAIL_MSG, "", None, "null", "None"] \
525526
and item["high_level"]["msg"] not in ["Generated image file does not exist", ""]
526527

528+
# Test dependencies first
527529
try:
528530
from pdf2image import convert_from_path
529531
from colormath.color_objects import sRGBColor, LabColor
530532
import squarify
531533
import matplotlib_venn
532534
import PIL
533-
example_pdf_path = "./vlmeval/dataset/utils/chartmimic/example.pdf"
534-
images = convert_from_path(example_pdf_path, dpi=350)
535-
images[0].save("./vlmeval/dataset/utils/chartmimic/example.png", "PNG")
536535
except ImportError as e:
537536
logging.critical(
538537
"Please follow the requirements (see vlmeval/dataset/utils/chartmimic/eval_req.txt) \
539-
to install dependency package for chartmimic evaluation.\n\
540-
And install poppler-utils in your system (e.g. sudo apt-get install poppler-utils)."
538+
to install dependency package for chartmimic evaluation."
541539
)
542540
raise e
541+
542+
# Test pdf2image functionality by creating a simple test PDF
543+
example_pdf_path = os.path.join(LMUDataRoot(), "chartmimic_test.pdf")
544+
output_png_path = os.path.join(LMUDataRoot(), "chartmimic_test.png")
545+
546+
try:
547+
# Create a simple test PDF using matplotlib
548+
import matplotlib.pyplot as plt
549+
fig, ax = plt.subplots(1, 1, figsize=(4, 3))
550+
ax.plot([1, 2, 3], [1, 4, 2])
551+
ax.set_title("Test Chart")
552+
plt.savefig(example_pdf_path, format='pdf')
553+
plt.close()
554+
555+
# Test pdf2image conversion
556+
images = convert_from_path(example_pdf_path, dpi=350)
557+
images[0].save(output_png_path, "PNG")
558+
logger.info("Successfully tested pdf2image functionality with generated test PDF")
559+
except Exception as e:
560+
logging.critical(
561+
"Please install poppler-utils in your system (e.g. sudo apt-get install poppler-utils)."
562+
)
563+
raise e
564+
finally:
565+
# Clean up test files
566+
if os.path.exists(example_pdf_path):
567+
os.remove(example_pdf_path)
568+
if os.path.exists(output_png_path):
569+
os.remove(output_png_path)
570+
543571
infer_data_all = load(eval_file).to_dict(orient="records")
544572

545573
suffix = eval_file.split(".")[-1]

vlmeval/dataset/utils/chartmimic/evaluator/chart_type_and_color.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def wrapper(
106106
clip_on=clip_on
107107
)
108108
return result
109+
wrapper.__name__ = func.__name__
109110
return wrapper
110111

111112

@@ -195,6 +196,7 @@ def wrapper(
195196
min_target_margin=min_target_margin
196197
)
197198
return result
199+
wrapper.__name__ = func.__name__
198200
return wrapper
199201

200202

@@ -266,6 +268,7 @@ def wrapper(
266268
margins=margins
267269
)
268270
return result
271+
wrapper.__name__ = func.__name__
269272
return wrapper
270273

271274

@@ -327,6 +330,7 @@ def wrapper(*args, **kwargs):
327330
return func(*args, **kwargs)
328331
return result
329332

333+
wrapper.__name__ = func.__name__
330334
return wrapper
331335

332336

@@ -471,7 +475,7 @@ def wrapper(*args, **kwargs):
471475
else:
472476
return func(*args, **kwargs)
473477
return result
474-
478+
wrapper.__name__ = func.__name__
475479
return wrapper
476480

477481

vlmeval/dataset/utils/chartmimic/evaluator/chart_type_evaluator_prefix.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1-
import inspect
2-
from matplotlib_venn._common import VennDiagram
3-
from matplotlib.patches import Ellipse, Circle
4-
from matplotlib.image import NonUniformImage
5-
from mpl_toolkits.mplot3d import Axes3D
6-
import networkx as nx
7-
import networkx.drawing.nx_pylab as nx_pylab
8-
import squarify
9-
from matplotlib.axes import Axes
1+
import os
2+
import sys
3+
# sys.path.insert(0, os.environ['PROJECT_PATH'])
4+
if os.environ["VLMEVAL_CHARTMIMIC_UTILS_PATH"] not in sys.path:
5+
sys.path.insert(0, os.environ["VLMEVAL_CHARTMIMIC_UTILS_PATH"])
6+
107
from matplotlib.projections.polar import PolarAxes
8+
import matplotlib.pyplot as plt
9+
from matplotlib.axes import Axes
10+
from matplotlib.axes._base import _process_plot_var_args
11+
import squarify
12+
import networkx.drawing.nx_pylab as nx_pylab
13+
import networkx as nx
14+
from mpl_toolkits.mplot3d import Axes3D
15+
from matplotlib.image import NonUniformImage
16+
from matplotlib.patches import Ellipse, Circle
17+
from matplotlib.tri._tripcolor import tripcolor
18+
from matplotlib_venn._common import VennDiagram
19+
import inspect
1120
import warnings
1221
warnings.filterwarnings("ignore", category=UserWarning)
1322
warnings.filterwarnings("ignore", category=DeprecationWarning)
@@ -79,6 +88,7 @@ def wrapper(
7988
clip_on=clip_on
8089
)
8190
return result
91+
wrapper.__name__ = func.__name__
8292
return wrapper
8393

8494

@@ -166,6 +176,7 @@ def wrapper(
166176
min_target_margin=min_target_margin
167177
)
168178
return result
179+
wrapper.__name__ = func.__name__
169180
return wrapper
170181

171182

@@ -235,6 +246,7 @@ def wrapper(
235246
margins=margins
236247
)
237248
return result
249+
wrapper.__name__ = func.__name__
238250
return wrapper
239251

240252

@@ -256,6 +268,7 @@ def wrapper(*args, **kwargs):
256268
return result
257269
else:
258270
return func(*args, **kwargs)
271+
wrapper.__name__ = func.__name__
259272
return wrapper
260273

261274

vlmeval/dataset/utils/chartmimic/evaluator/color_evaluator_prefix.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1-
# flake8: noqa
2-
from matplotlib.patches import Ellipse, Circle
3-
import inspect
4-
from matplotlib_venn._common import VennDiagram
5-
from matplotlib.image import NonUniformImage
6-
from matplotlib.projections.polar import PolarAxes
7-
import networkx.drawing.nx_pylab as nx_pylab
8-
import matplotlib.colors as mcolors
9-
from mpl_toolkits.mplot3d import Axes3D
10-
from matplotlib.axes._axes import Axes
11-
from matplotlib.axes._base import _process_plot_var_args
12-
import networkx as nx
13-
import numpy as np
14-
import matplotlib
15-
import sys
1+
# # flake8: noqa
162
import os
173
import squarify
184

195
import warnings
6+
207
warnings.filterwarnings("ignore", category=UserWarning)
218
warnings.filterwarnings("ignore", category=DeprecationWarning)
229
warnings.filterwarnings("ignore", category=FutureWarning)
2310

24-
# sys.path.insert(0, f'{os.environ["PROJECT_PATH"]}')
11+
import sys
2512

2613
if os.environ["VLMEVAL_CHARTMIMIC_UTILS_PATH"] not in sys.path:
2714
sys.path.insert(0, os.environ["VLMEVAL_CHARTMIMIC_UTILS_PATH"])
2815

16+
import networkx
17+
import matplotlib
18+
import matplotlib.pyplot as plt
19+
import numpy as np
20+
import networkx as nx
21+
from matplotlib.axes._base import _process_plot_var_args
22+
from matplotlib.axes._axes import Axes
23+
from mpl_toolkits.mplot3d import Axes3D
24+
import matplotlib.colors as mcolors
25+
import networkx.drawing.nx_pylab as nx_pylab
26+
from matplotlib.projections.polar import PolarAxes
27+
from matplotlib.image import NonUniformImage
28+
from matplotlib.patches import Ellipse, Circle
29+
from matplotlib_venn._common import VennDiagram
30+
import inspect
31+
from evaluator.color_utils import filter_color
32+
# from chart2code.utils.evaluator.color_utils import filter_color
33+
2934

3035
drawed_colors = []
3136
drawed_objects = {}
@@ -117,6 +122,7 @@ def wrapper(
117122
clip_on=clip_on
118123
)
119124
return result
125+
wrapper.__name__ = func.__name__
120126
return wrapper
121127

122128

@@ -216,6 +222,7 @@ def wrapper(
216222
min_target_margin=min_target_margin
217223
)
218224
return result
225+
wrapper.__name__ = func.__name__
219226
return wrapper
220227

221228

@@ -288,6 +295,7 @@ def wrapper(
288295
margins=margins
289296
)
290297
return result
298+
wrapper.__name__ = func.__name__
291299
return wrapper
292300

293301

@@ -378,7 +386,7 @@ def wrapper(*args, **kwargs):
378386
else:
379387
return func(*args, **kwargs)
380388
return result
381-
389+
wrapper.__name__ = func.__name__
382390
return wrapper
383391

384392

@@ -597,6 +605,7 @@ def wrapper(*args, **kwargs):
597605
return func(*args, **kwargs)
598606
return result
599607

608+
wrapper.__name__ = func.__name__
600609
return wrapper
601610

602611

vlmeval/dataset/utils/chartmimic/evaluator/legend_evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def wrapper(*args, **kwargs):
155155
156156
drawed_texts.append( (x, y, x_rel, y_rel, s) )
157157
return func(*args, **kwargs)
158-
158+
wrapper.__name__ = func.__name__
159159
return wrapper
160160
161161
RendererPdf.draw_text = log_function(RendererPdf.draw_text)

vlmeval/dataset/utils/chartmimic/evaluator/text_evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def wrapper(*args, **kwargs):
168168
169169
drawed_texts.append( (x, y, x_rel, y_rel, s) )
170170
return func(*args, **kwargs)
171-
171+
wrapper.__name__ = func.__name__
172172
return wrapper
173173
174174
RendererPdf.draw_text = log_function(RendererPdf.draw_text)
-18.8 KB
Binary file not shown.
-170 KB
Binary file not shown.

0 commit comments

Comments
 (0)