Ryan Chesler commited on
Commit
adb5d1e
·
1 Parent(s): d2e30b3

updated model path, readme and demo

Browse files
Files changed (3) hide show
  1. Demo.ipynb +2 -2
  2. README.md +6 -1
  3. nemotron_page_elements_v3/model.py +7 -7
Demo.ipynb CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:433fa0f144f075b75de5f2fa2925a808b6b15c18eaf58f591e09f50c3e121b9c
3
- size 1812492
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1abc855769ac788f46bc709cd33405fe02c816c68ad500a75ae82444998fbb61
3
+ size 1812701
README.md CHANGED
@@ -121,7 +121,12 @@ git clone https://huggingface.co/nvidia/nemotron-page-elements-v3
121
  ```
122
  git clone [email protected]:nvidia/nemotron-page-elements-v3
123
  ```
124
-
 
 
 
 
 
125
  2. Run the model using the following code:
126
 
127
  ```
 
121
  ```
122
  git clone [email protected]:nvidia/nemotron-page-elements-v3
123
  ```
124
+ Optional:
125
+ This can be installed as a package using pip
126
+ ```
127
+ cd nemotron-page-elements-v3
128
+ pip install -e .
129
+ ```
130
  2. Run the model using the following code:
131
 
132
  ```
nemotron_page_elements_v3/model.py CHANGED
@@ -36,15 +36,15 @@ def define_model(config_name: str = "page_element_v3", verbose: bool = True) ->
36
  if verbose:
37
  print(" -> Loading weights from", config.ckpt)
38
 
39
- # Locate 'weights.pth' in the same directory as this model.py file
40
- weights_path = os.path.join(os.path.dirname(__file__), "weights.pth")
41
- ckpt = torch.load(weights_path, map_location="cpu", weights_only=False)
42
- model.load_state_dict(ckpt["model"], strict=True)
43
-
 
44
  model = YoloXWrapper(model, config)
45
  return model.eval().to(config.device)
46
-
47
-
48
  def resize_pad(img: torch.Tensor, size: tuple) -> torch.Tensor:
49
  """
50
  Resizes and pads an image to a given size.
 
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
+
45
  model = YoloXWrapper(model, config)
46
  return model.eval().to(config.device)
47
+
 
48
  def resize_pad(img: torch.Tensor, size: tuple) -> torch.Tensor:
49
  """
50
  Resizes and pads an image to a given size.