Skip to content

Commit 23df9d8

Browse files
committed
[cleanup] fix deprecated APIs, remove dead code and unused imports
- Replace st.experimental_rerun() with st.rerun() in main_streamlit.py - Remove dead code after return statements in mm_utils.py - Remove unused divide_to_patches function in mm_utils.py - Remove duplicate os imports in hevc_feature_decoder_mv.py and step1_extract_video_features.py - Remove unused json import in inverted_index.py - Fix np.bool deprecation warning in pack_ocr.py with proper guards - Remove commented-out debug code in step1_extract_video_features.py
1 parent ca3dbe6 commit 23df9d8

6 files changed

Lines changed: 9 additions & 48 deletions

File tree

llava_next/llava/mm_utils.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -257,28 +257,6 @@ def resize_and_pad_image(image, target_resolution):
257257
return new_image
258258

259259

260-
def divide_to_patches(image, patch_size):
261-
"""
262-
Divides an image into patches of a specified size.
263-
264-
Args:
265-
image (PIL.Image.Image): The input image.
266-
patch_size (int): The size of each patch.
267-
268-
Returns:
269-
list: A list of PIL.Image.Image objects representing the patches.
270-
"""
271-
patches = []
272-
width, height = image.size
273-
for i in range(0, height, patch_size):
274-
for j in range(0, width, patch_size):
275-
box = (j, i, j + patch_size, i + patch_size)
276-
patch = image.crop(box)
277-
patches.append(patch)
278-
279-
return patches
280-
281-
282260
def get_anyres_image_grid_shape(image_size, grid_pinpoints, patch_size):
283261
"""
284262
Calculate the shape of the image patch grid after the preprocessing for images of any resolution.
@@ -352,23 +330,6 @@ def process_anyres_image(image, processor, grid_pinpoints):
352330
grid_thw = [1, best_resolution[1] // 14, best_resolution[0] // 14]
353331
return {'pixel_values': torch.cat(image_patches, dim=0), 'grid_thw': grid_thw}
354332

355-
patches = divide_to_patches(image_padded, processor.crop_size["height"])
356-
357-
# FIXME: this seems to be a bug that it resizes instead of pad.
358-
# but to keep it consistent with previous, i will keep it as it is
359-
# TODO: uncomment below to ablate with the padding
360-
if isinstance(processor.size, dict):
361-
shortest_edge = processor.size["shortest_edge"]
362-
else:
363-
shortest_edge = min(processor.size)
364-
image_original_resize = image.resize((shortest_edge, shortest_edge))
365-
# image_padded_square = expand2square(image, tuple(int(x*255) for x in processor.image_mean))
366-
# image_original_resize = image_padded_square.resize((processor.size['shortest_edge'], processor.size['shortest_edge']))
367-
368-
image_patches = [image_original_resize] + patches
369-
image_patches = [processor.preprocess(image_patch, return_tensors="pt")["pixel_values"][0] for image_patch in image_patches]
370-
return torch.stack(image_patches, dim=0)
371-
372333

373334
def load_image_from_base64(image):
374335
return Image.open(BytesIO(base64.b64decode(image)))

tools/inverted_index.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22
import pickle
3-
import json
43
import argparse
54
from collections import defaultdict
65
from pathlib import Path

tools/kmeans/step1_extract_video_features.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,6 @@ def main(args):
378378
my_videos = all_videos
379379
print(f"[Rank {rank}] Processing all {len(my_videos)} videos")
380380

381-
# with open(f"{args.input}_padding.txt", 'w') as f:
382-
# f.writelines(all_videos)
383381
# Load checkpoint
384382
output_dir = Path(args.output)
385383
output_dir.mkdir(parents=True, exist_ok=True)
@@ -448,8 +446,7 @@ def main(args):
448446
print(f"Final feature shape: {cleaned_features.shape}")
449447
elif pad_count == features_per_file:
450448
# 整个最后一个文件都是 padding,直接删掉文件更合理
451-
import os
452-
os.remove(str(last_npy_path))
449+
last_npy_path.unlink()
453450
print(f"Removed entire last file since it was all padding ({pad_count} rows).")
454451
else:
455452
# 需要继续往前删前一个文件,当前代码未实现,给出提示

tools/main_streamlit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def main():
462462
# 保存路径到会话状态
463463
st.session_state.index_file = index_file
464464
st.session_state.video_list_file = video_list_file
465-
st.experimental_rerun()
465+
st.rerun()
466466
else:
467467
st.error("请输入所有必要的文件路径")
468468

@@ -486,7 +486,7 @@ def main():
486486
del st.session_state.index_file
487487
if 'video_list_file' in st.session_state:
488488
del st.session_state.video_list_file
489-
st.experimental_rerun()
489+
st.rerun()
490490

491491
# 配置参数
492492
st.sidebar.subheader("可视化配置")

tools/tools_for_hevc/hevc_feature_decoder_mv.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,6 @@ def _readFrame(self):
703703
self.height + (self.height >> 1), self.width
704704
)
705705

706-
import os
707706
if int(os.environ.get('UMT_HEVC_Y_ONLY', '1')) != 0:
708707
y = all_yuv_data[:self.height, :self.width]
709708
y_res = all_yuv_data_residual[:self.height, :self.width]

tools/tools_for_ocr/pack_ocr.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import os
22
import json
33
import pathlib
4+
import warnings
45
import numpy as np
5-
np.bool = np.bool_ # 解决 mxnet 与 numpy 冲突
6+
# mxnet uses deprecated np.bool; suppress warning and patch
7+
with warnings.catch_warnings():
8+
warnings.filterwarnings('ignore', category=DeprecationWarning)
9+
if not hasattr(np, 'bool') or np.bool is bool:
10+
np.bool = np.bool_
611

712
import mxnet as mx
813
import mxnet.recordio as recordio

0 commit comments

Comments
 (0)