remove_model_weights_from_wheel

#9
by jdye64 - opened
MANIFEST.in CHANGED
@@ -1,5 +1,6 @@
1
  include README.md
2
  include THIRD_PARTY_NOTICES.md
3
- recursive-include nemotron_page_elements_v3
 
4
 
5
 
 
1
  include README.md
2
  include THIRD_PARTY_NOTICES.md
3
+ recursive-include nemotron_page_elements_v3 *.py *.json *.png
4
+ exclude nemotron_page_elements_v3/weights.pth
5
 
6
 
nemotron_page_elements_v3/model.py CHANGED
@@ -10,8 +10,13 @@ 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 nemotron_page_elements_v3.yolox.boxes import postprocess
14
 
 
 
 
 
15
 
16
  def define_model(config_name: str = "page_element_v3", verbose: bool = True) -> nn.Module:
17
  """
@@ -32,13 +37,18 @@ def define_model(config_name: str = "page_element_v3", verbose: bool = True) ->
32
  config = exp_module.Exp()
33
  model = config.get_model()
34
 
35
- # Load weights
 
 
 
 
 
 
 
 
36
  if verbose:
37
- print(" -> Loading weights from", config.ckpt)
38
 
39
- # Find package directory and load weights (nemotron_page_elements_v3)
40
- package_dir = os.path.dirname(os.path.abspath(__file__))
41
- weights_path = os.path.join(package_dir, "weights.pth")
42
  state_dict = torch.load(weights_path, map_location="cpu", weights_only=False)
43
  model.load_state_dict(state_dict["model"], strict=True)
44
 
 
10
  import torch.nn as nn
11
  import torch.nn.functional as F
12
  from typing import Dict, List, Tuple, Union
13
+ from huggingface_hub import hf_hub_download
14
  from nemotron_page_elements_v3.yolox.boxes import postprocess
15
 
16
+ # HuggingFace repository for downloading model weights
17
+ HF_REPO_ID = "nvidia/nemotron-page-elements-v3"
18
+ WEIGHTS_FILENAME = "nemotron_page_elements_v3/weights.pth"
19
+
20
 
21
  def define_model(config_name: str = "page_element_v3", verbose: bool = True) -> nn.Module:
22
  """
 
37
  config = exp_module.Exp()
38
  model = config.get_model()
39
 
40
+ # Download weights from HuggingFace Hub (cached locally after first download)
41
+ if verbose:
42
+ print(f" -> Downloading/loading weights from HuggingFace: {HF_REPO_ID}")
43
+
44
+ weights_path = hf_hub_download(
45
+ repo_id=HF_REPO_ID,
46
+ filename=WEIGHTS_FILENAME,
47
+ )
48
+
49
  if verbose:
50
+ print(f" -> Weights cached at: {weights_path}")
51
 
 
 
 
52
  state_dict = torch.load(weights_path, map_location="cpu", weights_only=False)
53
  model.load_state_dict(state_dict["model"], strict=True)
54
 
pyproject.toml CHANGED
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
 
5
  [project]
6
  name = "nemotron-page-elements-v3"
7
- version = "3.0.0"
8
  description = "NVIDIA Nemotron Page Elements v3: A specialized YOLOX-based object detection model for identifying tables, charts, infographics, titles, headers/footers, and text in document pages"
9
  readme = "README.md"
10
  requires-python = ">=3.8"
@@ -58,6 +58,7 @@ dependencies = [
58
  "tensorboard",
59
  "pycocotools>=2.0.2",
60
  "onnx>=1.13.0",
 
61
  ]
62
 
63
  [project.optional-dependencies]
@@ -83,5 +84,5 @@ where = ["."]
83
  include = ["nemotron_page_elements_v3*"]
84
 
85
  [tool.setuptools.package-data]
86
- "nemotron_page_elements_v3" = ["*.json", "*.pth", "*.png"]
87
 
 
4
 
5
  [project]
6
  name = "nemotron-page-elements-v3"
7
+ version = "3.0.1"
8
  description = "NVIDIA Nemotron Page Elements v3: A specialized YOLOX-based object detection model for identifying tables, charts, infographics, titles, headers/footers, and text in document pages"
9
  readme = "README.md"
10
  requires-python = ">=3.8"
 
58
  "tensorboard",
59
  "pycocotools>=2.0.2",
60
  "onnx>=1.13.0",
61
+ "huggingface_hub",
62
  ]
63
 
64
  [project.optional-dependencies]
 
84
  include = ["nemotron_page_elements_v3*"]
85
 
86
  [tool.setuptools.package-data]
87
+ "nemotron_page_elements_v3" = ["*.json", "*.png"]
88