.gitignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ build/
2
+ dist/
3
+ *.egg-info/
4
+ *.pyc
5
+ *.pyo
6
+ *.pyd
Demo.ipynb CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:777844f15f935804cd331020a2338c7db3670a96b0dc6d3430b2602cde666e68
3
- size 989346
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4c6af3fabb5d255609ad3954c451015dbf565d3855ae54440f99429ba6978f55
3
+ size 878101
MANIFEST.in ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ include README.md
2
+ include THIRD_PARTY_NOTICES.md
3
+ recursive-include nemotron_graphic_elements_v1
README.md CHANGED
@@ -134,7 +134,12 @@ git clone https://huggingface.co/nvidia/nemotron-graphic-elements-v1
134
  ```
135
  git clone [email protected]:nvidia/nemotron-graphic-elements-v1
136
  ```
137
-
 
 
 
 
 
138
  2. Run the model using the following code:
139
 
140
  ```
@@ -143,8 +148,8 @@ import numpy as np
143
  import matplotlib.pyplot as plt
144
  from PIL import Image
145
 
146
- from model import define_model
147
- from utils import plot_sample, postprocess_preds_graphic_element, reformat_for_plotting
148
 
149
  # Load image
150
  path = "./example.png"
 
134
  ```
135
  git clone [email protected]:nvidia/nemotron-graphic-elements-v1
136
  ```
137
+ Optional:
138
+ This can be installed as a package using pip
139
+ ```
140
+ cd nemotron-graphic-elements-v3
141
+ pip install -e .
142
+ ```
143
  2. Run the model using the following code:
144
 
145
  ```
 
148
  import matplotlib.pyplot as plt
149
  from PIL import Image
150
 
151
+ from nemotron_graphic_elements_v1.model import define_model
152
+ from nemotron_graphic_elements_v1.utils import plot_sample, postprocess_preds_graphic_element, reformat_for_plotting
153
 
154
  # Load image
155
  path = "./example.png"
nemotron_graphic_elements_v1/__init__.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ """
5
+ Nemotron Graphic Elements v1
6
+
7
+ A specialized object detection system designed to identify and extract key elements
8
+ from charts and graphs. Based on YOLOX architecture.
9
+ """
10
+
11
+ __version__ = "1.0.0"
12
+
13
+ from .model import define_model
14
+ from .utils import (
15
+ plot_sample,
16
+ postprocess_preds_graphic_element,
17
+ reformat_for_plotting,
18
+ reorder_boxes,
19
+ COLORS,
20
+ )
21
+ from .graphic_element_v1 import Exp
22
+
23
+ __all__ = [
24
+ "define_model",
25
+ "Exp",
26
+ "plot_sample",
27
+ "postprocess_preds_graphic_element",
28
+ "reformat_for_plotting",
29
+ "reorder_boxes",
30
+ "COLORS",
31
+ ]
32
+
config.json → nemotron_graphic_elements_v1/config.json RENAMED
File without changes
graphic_element_v1.py → nemotron_graphic_elements_v1/graphic_element_v1.py RENAMED
@@ -1,6 +1,7 @@
1
  # SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
  # SPDX-License-Identifier: Apache-2.0
3
 
 
4
  import torch
5
  import torch.nn as nn
6
  from typing import List, Tuple
@@ -18,7 +19,9 @@ class Exp:
18
  def __init__(self) -> None:
19
  """Initialize the configuration with default parameters."""
20
  self.name: str = "graphic-element-v1"
21
- self.ckpt: str = "weights.pth"
 
 
22
  self.device: str = "cuda:0" if torch.cuda.is_available() else "cpu"
23
 
24
  # YOLOX architecture parameters
@@ -61,7 +64,7 @@ class Exp:
61
  Returns:
62
  nn.Module: The YOLOX model with configured parameters.
63
  """
64
- from yolox import YOLOX, YOLOPAFPN, YOLOXHead
65
 
66
  # Build model
67
  if getattr(self, "model", None) is None:
 
1
  # SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
  # SPDX-License-Identifier: Apache-2.0
3
 
4
+ import os
5
  import torch
6
  import torch.nn as nn
7
  from typing import List, Tuple
 
19
  def __init__(self) -> None:
20
  """Initialize the configuration with default parameters."""
21
  self.name: str = "graphic-element-v1"
22
+ # Use package directory for weights path
23
+ package_dir = os.path.dirname(os.path.abspath(__file__))
24
+ self.ckpt: str = os.path.join(package_dir, "weights.pth")
25
  self.device: str = "cuda:0" if torch.cuda.is_available() else "cpu"
26
 
27
  # YOLOX architecture parameters
 
64
  Returns:
65
  nn.Module: The YOLOX model with configured parameters.
66
  """
67
+ from .yolox import YOLOX, YOLOPAFPN, YOLOXHead
68
 
69
  # Build model
70
  if getattr(self, "model", None) is None:
model.py → nemotron_graphic_elements_v1/model.py RENAMED
@@ -10,7 +10,7 @@ import numpy.typing as npt
10
  import torch.nn as nn
11
  import torch.nn.functional as F
12
  from typing import Dict, List, Tuple, Union
13
- from yolox.boxes import postprocess
14
 
15
 
16
  def define_model(config_name: str = "graphic_element_v1", verbose: bool = True) -> nn.Module:
@@ -24,11 +24,10 @@ def define_model(config_name: str = "graphic_element_v1", verbose: bool = True)
24
  Returns:
25
  torch.nn.Module: The initialized YOLOX model.
26
  """
27
- # Load model from exp_file
28
- sys.path.append(os.path.dirname(config_name))
29
- exp_module = importlib.import_module(os.path.basename(config_name).split(".")[0])
30
-
31
- config = exp_module.Exp()
32
  model = config.get_model()
33
 
34
  # Load weights
 
10
  import torch.nn as nn
11
  import torch.nn.functional as F
12
  from typing import Dict, List, Tuple, Union
13
+ from .yolox.boxes import postprocess
14
 
15
 
16
  def define_model(config_name: str = "graphic_element_v1", verbose: bool = True) -> nn.Module:
 
24
  Returns:
25
  torch.nn.Module: The initialized YOLOX model.
26
  """
27
+ # Import the config class
28
+ from .graphic_element_v1 import Exp
29
+
30
+ config = Exp()
 
31
  model = config.get_model()
32
 
33
  # Load weights
{post_processing → nemotron_graphic_elements_v1/post_processing}/graphic_elt_pp.py RENAMED
File without changes
utils.py → nemotron_graphic_elements_v1/utils.py RENAMED
File without changes
weights.pth → nemotron_graphic_elements_v1/weights.pth RENAMED
File without changes
{yolox → nemotron_graphic_elements_v1/yolox}/__init__.py RENAMED
File without changes
{yolox → nemotron_graphic_elements_v1/yolox}/boxes.py RENAMED
File without changes
{yolox → nemotron_graphic_elements_v1/yolox}/darknet.py RENAMED
File without changes
{yolox → nemotron_graphic_elements_v1/yolox}/network_blocks.py RENAMED
File without changes
{yolox → nemotron_graphic_elements_v1/yolox}/yolo_fpn.py RENAMED
File without changes
{yolox → nemotron_graphic_elements_v1/yolox}/yolo_head.py RENAMED
File without changes
{yolox → nemotron_graphic_elements_v1/yolox}/yolo_pafpn.py RENAMED
File without changes
{yolox → nemotron_graphic_elements_v1/yolox}/yolox.py RENAMED
File without changes
pyproject.toml ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "nemotron-graphic-elements-v1"
7
+ version = "1.0.0"
8
+ description = "NVIDIA Nemotron Graphic Elements v1 - A specialized object detection system for identifying and extracting key elements from charts and graphs"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text = "NVIDIA Open Model License"}
12
+ authors = [
13
+ {name = "NVIDIA Corporation", email = "[email protected]"}
14
+ ]
15
+ keywords = ["object-detection", "yolox", "charts", "graphics", "pdf-ingestion", "computer-vision"]
16
+ classifiers = [
17
+ "Development Status :: 5 - Production/Stable",
18
+ "Intended Audience :: Developers",
19
+ "Intended Audience :: Science/Research",
20
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
21
+ "Topic :: Scientific/Engineering :: Image Recognition",
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.8",
24
+ "Programming Language :: Python :: 3.9",
25
+ "Programming Language :: Python :: 3.10",
26
+ "Programming Language :: Python :: 3.11",
27
+ ]
28
+
29
+ dependencies = [
30
+ "torch>=2.0.0",
31
+ "numpy>=1.21.0",
32
+ "matplotlib>=3.5.0",
33
+ "pandas>=1.3.0",
34
+ "Pillow>=9.0.0",
35
+ ]
36
+
37
+ [project.optional-dependencies]
38
+ dev = [
39
+ "jupyter>=1.0.0",
40
+ "notebook>=6.4.0",
41
+ ]
42
+
43
+ [project.urls]
44
+ Homepage = "https://huggingface.co/nvidia/nemotron-graphic-elements-v1"
45
+ Documentation = "https://huggingface.co/nvidia/nemotron-graphic-elements-v1"
46
+ Repository = "https://huggingface.co/nvidia/nemotron-graphic-elements-v1"
47
+ "Bug Reports" = "https://app.intigriti.com/programs/nvidia/nvidiavdp/detail"
48
+
49
+ [tool.setuptools]
50
+ packages = ["nemotron_graphic_elements_v1", "nemotron_graphic_elements_v1.yolox", "nemotron_graphic_elements_v1.post_processing"]
51
+
52
+ [tool.setuptools.package-data]
53
+ "nemotron_graphic_elements_v1" = ["*.pth", "*.json", "*.png"]
54
+
setup.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # SPDX-FileCopyrightText: Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from setuptools import setup, find_packages
6
+
7
+ # For compatibility with older tools, but pyproject.toml is the primary configuration
8
+ setup(
9
+ packages=find_packages(include=['nemotron_graphic_elements_v1', 'nemotron_graphic_elements_v1.*']),
10
+ )
11
+