hjxdl 0.1.74__py3-none-any.whl → 0.1.76__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hdl/_version.py +2 -2
- hdl/utils/llm/vis.py +26 -10
- {hjxdl-0.1.74.dist-info → hjxdl-0.1.76.dist-info}/METADATA +1 -1
- {hjxdl-0.1.74.dist-info → hjxdl-0.1.76.dist-info}/RECORD +6 -6
- {hjxdl-0.1.74.dist-info → hjxdl-0.1.76.dist-info}/WHEEL +0 -0
- {hjxdl-0.1.74.dist-info → hjxdl-0.1.76.dist-info}/top_level.txt +0 -0
hdl/_version.py
CHANGED
hdl/utils/llm/vis.py
CHANGED
@@ -280,7 +280,8 @@ class ImgHandler:
|
|
280
280
|
def vec_pics_todb(
|
281
281
|
self,
|
282
282
|
images: list[str],
|
283
|
-
|
283
|
+
conn=None,
|
284
|
+
print_idx_info: bool = False,
|
284
285
|
):
|
285
286
|
"""Save image features to a Redis database.
|
286
287
|
|
@@ -293,9 +294,12 @@ class ImgHandler:
|
|
293
294
|
Example:
|
294
295
|
vec_pics_todb(images=['image1.jpg', 'image2.jpg'])
|
295
296
|
"""
|
296
|
-
sorted_imgs = natsort.natsorted(images)
|
297
|
+
# sorted_imgs = natsort.natsorted(images)
|
298
|
+
sorted_imgs = images
|
297
299
|
img_feats = self.get_img_features(sorted_imgs, to_numpy=True)
|
298
|
-
|
300
|
+
if conn is None:
|
301
|
+
conn = self.db_conn
|
302
|
+
pipeline = conn.pipeline()
|
299
303
|
for img_file, emb in tqdm(zip(sorted_imgs, img_feats)):
|
300
304
|
# 初始化 Redis,先使用 img 文件名作为 Key 和 Value,后续再更新为图片特征向量
|
301
305
|
# pipeline.json().set(img_file, "$", img_file)
|
@@ -325,7 +329,7 @@ class ImgHandler:
|
|
325
329
|
prefix=["pic-"],
|
326
330
|
index_type=IndexType.JSON
|
327
331
|
)
|
328
|
-
res =
|
332
|
+
res = conn.ft(
|
329
333
|
self.pic_idx_name
|
330
334
|
).create_index(
|
331
335
|
fields=schema,
|
@@ -336,12 +340,17 @@ class ImgHandler:
|
|
336
340
|
print(self.pic_idx_info)
|
337
341
|
|
338
342
|
@property
|
339
|
-
def pic_idx_info(
|
340
|
-
|
343
|
+
def pic_idx_info(
|
344
|
+
self,
|
345
|
+
conn=None
|
346
|
+
):
|
347
|
+
if conn is None:
|
348
|
+
conn = self.db_conn
|
349
|
+
res = conn.ping()
|
341
350
|
print("redis connected:", res)
|
342
351
|
# vector_idx_name = "idx:pic_idx"
|
343
352
|
# 从 Redis 数据库中读取索引状态
|
344
|
-
info =
|
353
|
+
info = conn.ft(self.pic_idx_name).info()
|
345
354
|
# 获取索引状态中的 num_docs 和 hash_indexing_failures
|
346
355
|
num_docs = info["num_docs"]
|
347
356
|
indexing_failures = info["hash_indexing_failures"]
|
@@ -354,6 +363,7 @@ class ImgHandler:
|
|
354
363
|
emb_query,
|
355
364
|
num_max: int = 3,
|
356
365
|
extra_params: dict = None,
|
366
|
+
conn=None
|
357
367
|
):
|
358
368
|
"""Search for similar embeddings in the database.
|
359
369
|
|
@@ -375,8 +385,10 @@ class ImgHandler:
|
|
375
385
|
)
|
376
386
|
if extra_params is None:
|
377
387
|
extra_params = {}
|
388
|
+
if conn is None:
|
389
|
+
conn = self.db_conn
|
378
390
|
result_docs = (
|
379
|
-
|
391
|
+
conn.ft("idx:pic_idx")
|
380
392
|
.search(
|
381
393
|
query,
|
382
394
|
{
|
@@ -396,7 +408,8 @@ class ImgHandler:
|
|
396
408
|
self,
|
397
409
|
img,
|
398
410
|
num_max: int = 3,
|
399
|
-
extra_params: dict = None
|
411
|
+
extra_params: dict = None,
|
412
|
+
conn=None
|
400
413
|
):
|
401
414
|
"""Search for similar images in the database based on the input image.
|
402
415
|
|
@@ -411,10 +424,13 @@ class ImgHandler:
|
|
411
424
|
emb_query = self.get_img_features(
|
412
425
|
[img], to_numpy=True
|
413
426
|
).astype(np.float32)[0].tobytes()
|
427
|
+
if conn is None:
|
428
|
+
conn = self.db_conn
|
414
429
|
results = self.emb_search(
|
415
430
|
emb_query=emb_query,
|
416
431
|
num_max=num_max,
|
417
|
-
extra_params=extra_params
|
432
|
+
extra_params=extra_params,
|
433
|
+
conn=conn
|
418
434
|
)
|
419
435
|
return results
|
420
436
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
hdl/__init__.py,sha256=GffnD0jLJdhkd-vo989v40N90sQbofkayRBwxc6TVhQ,72
|
2
|
-
hdl/_version.py,sha256
|
2
|
+
hdl/_version.py,sha256=XDO16ALCEfcHVQNkdeFRVlrPkVueFpt5S-psvPJP1Sc,413
|
3
3
|
hdl/args/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
hdl/args/loss_args.py,sha256=s7YzSdd7IjD24rZvvOrxLLFqMZQb9YylxKeyelSdrTk,70
|
5
5
|
hdl/controllers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -131,12 +131,12 @@ hdl/utils/llm/chat.py,sha256=sk7Lw5Oa30k-l2fnJknkMmTc5zkBeEKsR981aeFhH5s,11907
|
|
131
131
|
hdl/utils/llm/embs.py,sha256=Tf0FOYrOFZp7qQpEPiSCXzlgyHH0X9HVTUtsup74a9E,7174
|
132
132
|
hdl/utils/llm/extract.py,sha256=2sK_WJzmYIc8iuWaM9DA6Nw3_6q1O4lJ5pKpcZo-bBA,6512
|
133
133
|
hdl/utils/llm/llama_chat.py,sha256=watcHGOaz-bv3x-yDucYlGk5f8FiqfFhwWogrl334fk,4387
|
134
|
-
hdl/utils/llm/vis.py,sha256=
|
134
|
+
hdl/utils/llm/vis.py,sha256=2s0U9wR9K1jSS8jtLGUliA4C_NGULoy5aayAxU6MN_o,14105
|
135
135
|
hdl/utils/schedulers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
136
136
|
hdl/utils/schedulers/norm_lr.py,sha256=bDwCmdEK-WkgxQMFBiMuchv8Mm7C0-GZJ6usm-PQk14,4461
|
137
137
|
hdl/utils/weather/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
138
138
|
hdl/utils/weather/weather.py,sha256=k11o6wM15kF8b9NMlEfrg68ak-SfSYLN3nOOflFUv-I,4381
|
139
|
-
hjxdl-0.1.
|
140
|
-
hjxdl-0.1.
|
141
|
-
hjxdl-0.1.
|
142
|
-
hjxdl-0.1.
|
139
|
+
hjxdl-0.1.76.dist-info/METADATA,sha256=ff40qi9oE0kcWS2gSj0I3aHbaQZOEp64U3hCAZoekQs,903
|
140
|
+
hjxdl-0.1.76.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
|
141
|
+
hjxdl-0.1.76.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
|
142
|
+
hjxdl-0.1.76.dist-info/RECORD,,
|
File without changes
|
File without changes
|