sidchak-gh commited on
Commit
d44acb9
·
1 Parent(s): bb3ea41

fix np.float replacement logic

Browse files
Files changed (2) hide show
  1. Dockerfile +3 -2
  2. fix_code.py +36 -0
Dockerfile CHANGED
@@ -29,8 +29,9 @@ RUN sed -i '/lap/d' requirements.txt && \
29
  RUN sed -i 's/onnx==1.8.1/onnx>=1.9.0/g' requirements.txt && \
30
  sed -i 's/onnxruntime==1.8.0/onnxruntime>=1.8.0/g' requirements.txt
31
 
32
- # Fix np.float in python files
33
- RUN find . -name "*.py" -exec sed -i 's/np.float/float/g' {} +
 
34
 
35
  # Pre-install build dependencies (Required for cython_bbox calculation)
36
  RUN uv pip install --system cython numpy
 
29
  RUN sed -i 's/onnx==1.8.1/onnx>=1.9.0/g' requirements.txt && \
30
  sed -i 's/onnxruntime==1.8.0/onnxruntime>=1.8.0/g' requirements.txt
31
 
32
+ # Fix np.float in python files using safe script
33
+ COPY fix_code.py /app/ByteTrack/
34
+ RUN python fix_code.py && rm fix_code.py
35
 
36
  # Pre-install build dependencies (Required for cython_bbox calculation)
37
  RUN uv pip install --system cython numpy
fix_code.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+
4
+ def fix_file(path):
5
+ with open(path, "r", encoding="utf-8", errors="ignore") as f:
6
+ content = f.read()
7
+
8
+ # Replace deprecated numpy aliases with python builtins
9
+ # Use negative lookahead to avoid matching keys like np.float32, np.int64, etc.
10
+
11
+ # np.float -> float
12
+ new_content = re.sub(r'np\.float(?![0-9_a-zA-Z])', 'float', content)
13
+
14
+ # np.int -> int (deprecated in recent numpy)
15
+ new_content = re.sub(r'np\.int(?![0-9_a-zA-Z])', 'int', new_content)
16
+
17
+ # np.bool -> bool (deprecated in recent numpy)
18
+ new_content = re.sub(r'np\.bool(?![0-9_a-zA-Z])', 'bool', new_content)
19
+
20
+ if new_content != content:
21
+ print(f"Fixed deprecated types in: {path}")
22
+ with open(path, "w", encoding="utf-8") as f:
23
+ f.write(new_content)
24
+
25
+ def main():
26
+ print("Scanning for deprecated numpy types...")
27
+ for root, dirs, files in os.walk("."):
28
+ if ".git" in root: continue
29
+ for file in files:
30
+ if file.endswith(".py"):
31
+ path = os.path.join(root, file)
32
+ fix_file(path)
33
+ print("Fix complete.")
34
+
35
+ if __name__ == "__main__":
36
+ main()