bump
This commit is contained in:
+14
-17
@@ -1,31 +1,28 @@
|
||||
import open_clip
|
||||
import torch
|
||||
import functools
|
||||
import onnxruntime as ort
|
||||
|
||||
do_load = True
|
||||
if do_load:
|
||||
|
||||
#model_name = 'hf-hub:timm/ViT-L-16-SigLIP2-512'
|
||||
# model, preprocess = open_clip.create_model_from_pretrained('hf-hub:timm/ViT-L-16-SigLIP2-512')
|
||||
|
||||
|
||||
model_name = 'ViT-SO400M-14-SigLIP-384'
|
||||
pretrained_name = 'webli'
|
||||
model, _, preprocess = open_clip.create_model_and_transforms(model_name, pretrained=pretrained_name)
|
||||
device = 'cpu'
|
||||
model.eval()
|
||||
model_name = 'ViT-SO400M-16-SigLIP2-512'
|
||||
tokenizer = open_clip.get_tokenizer(model_name)
|
||||
#onnx_path = "/home/thebears/Source/ml/clip_extract/text/ViT-SO400M-16-SigLIP2-512_text"
|
||||
onnx_path = "/home/thebears/Source/ml/clip_extract/text/ViT-SO400M-16-SigLIP2-512_text_optimized"
|
||||
ort_sess = ort.InferenceSession(onnx_path)
|
||||
|
||||
from bottle import route, run, template, request, debug
|
||||
@route('/encode')
|
||||
def get_matches():
|
||||
query = request.query.get('query','A large bird eating corn')
|
||||
query = request.query.get('query',None)
|
||||
if query is None:
|
||||
return None
|
||||
return execute_model(query)
|
||||
|
||||
@functools.cache
|
||||
def execute_model(query):
|
||||
with torch.no_grad():
|
||||
text_tokenized = tokenizer(query)
|
||||
vec = model.encode_text(text_tokenized).detach().cpu().tolist()
|
||||
|
||||
vec = ort_sess.run(None, {'tokenized': text_tokenized.numpy() })[0].tolist()
|
||||
return {'vector':vec}
|
||||
|
||||
|
||||
|
||||
debug(True)
|
||||
run(host='0.0.0.0', port=53004, server='bjoern')
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
print('hello')
|
||||
# %%
|
||||
import open_clip
|
||||
import torch
|
||||
|
||||
do_load = True
|
||||
if do_load:
|
||||
|
||||
|
||||
model_name = 'hf-hub:timm/ViT-L-16-SigLIP2-512'
|
||||
# pretrained_name = 'webli'
|
||||
model, preprocess = open_clip.create_model_from_pretrained('hf-hub:timm/ViT-L-16-SigLIP2-512')
|
||||
|
||||
# model, _, preprocess = open_clip.create_model_and_transforms(model_name, pretrained=pretrained_name)
|
||||
device = 'cpu'
|
||||
model.eval()
|
||||
tokenizer = open_clip.get_tokenizer(model_name)
|
||||
@@ -1,22 +1,31 @@
|
||||
from pymilvus import MilvusClient, DataType
|
||||
|
||||
|
||||
import os
|
||||
from tqdm import tqdm
|
||||
client = MilvusClient(
|
||||
uri="http://localhost:19530"
|
||||
)
|
||||
#for x in client.list_collections():
|
||||
# client.drop_collection(x)
|
||||
|
||||
|
||||
paths_scan = ['/srv/ftp_tcc','/srv/ftp','/srv/ftp_local/']
|
||||
|
||||
outff = list()
|
||||
for xpp in paths_scan:
|
||||
outff.extend([x.path for x in os.scandir(xpp) if x.is_dir()])
|
||||
|
||||
|
||||
|
||||
|
||||
out = [x.split('/')[3] for x in outff]
|
||||
|
||||
# %%
|
||||
|
||||
import os
|
||||
out = os.listdir('/mergedfs/ftp/')
|
||||
|
||||
# %%
|
||||
for cam in out:
|
||||
c_collections = set(client.list_collections())
|
||||
for cam in tqdm(out):
|
||||
c_col_name = f"nuggets_{cam}_so400m_siglip2"
|
||||
if c_col_name in c_collections:
|
||||
print(f"Skipping {c_col_name}")
|
||||
continue
|
||||
else:
|
||||
print(f"Creating {c_col_name}")
|
||||
schema = MilvusClient.create_schema(
|
||||
auto_id=False,
|
||||
nenable_dynamic_field=False,
|
||||
@@ -25,7 +34,7 @@ for cam in out:
|
||||
schema.add_field(field_name="filepath", datatype=DataType.VARCHAR, max_length=128)
|
||||
schema.add_field(field_name="frame_number", datatype=DataType.INT32)
|
||||
schema.add_field(field_name="date", datatype=DataType.VARCHAR, max_length=len('20241220'), is_partition_key=True)
|
||||
schema.add_field(field_name="so400m", datatype=DataType.FLOAT16_VECTOR, dim=1024)
|
||||
schema.add_field(field_name="so400m", datatype=DataType.FLOAT16_VECTOR, dim=1152)
|
||||
|
||||
|
||||
index_params = client.prepare_index_params()
|
||||
@@ -40,7 +49,7 @@ for cam in out:
|
||||
|
||||
index_params.add_index(
|
||||
field_name="so400m",
|
||||
index_type="IVF_SQ8",
|
||||
index_type="DISKANN",
|
||||
metric_type="COSINE",
|
||||
params={'nlist':128})
|
||||
|
||||
@@ -49,16 +58,13 @@ for cam in out:
|
||||
index_type='Trie')
|
||||
|
||||
client.create_collection(
|
||||
collection_name=f"nuggets_{cam}_so400m_siglip2",
|
||||
collection_name=c_col_name,
|
||||
schema=schema,
|
||||
index_params=index_params
|
||||
)
|
||||
print(cam)
|
||||
|
||||
#res = client.get_load_state( collection_name="nuggets_ptz_so400m_siglip2")
|
||||
#res = client.load_collection(collection_name="nuggets_so400m")
|
||||
|
||||
#import numpy
|
||||
|
||||
|
||||
|
||||
|
||||
#c = numpy.load('/srv/ftp_tcc/leopards1/2025/07/18/Leopards1_00_20250718170024.oclip_embeds.npz')
|
||||
|
||||
@@ -60,7 +60,7 @@ def upload_vector_file(vector_file_to_upload):
|
||||
|
||||
|
||||
|
||||
root_path = '/srv/ftp/railing/2024'
|
||||
root_path = '/srv/ftp/railing/2026/'
|
||||
to_put = list()
|
||||
for root, dirs, files in os.walk(root_path):
|
||||
for x in files:
|
||||
|
||||
+23
-22
@@ -8,51 +8,54 @@ import traceback
|
||||
from bottle import route, run, template, request, debug
|
||||
import time
|
||||
import prettyprinter
|
||||
# %%
|
||||
|
||||
TIMEOUT=2
|
||||
# %%
|
||||
TIMEOUT=10
|
||||
|
||||
#collection_name = "nuggets_{camera}_so400m_siglip2"
|
||||
collection_name = "nuggets_{camera}_so400m"
|
||||
|
||||
collection_name = "nuggets_{camera}_so400m_siglip2"
|
||||
client = MilvusClient(
|
||||
uri="http://localhost:19530"
|
||||
)
|
||||
# %%
|
||||
|
||||
|
||||
|
||||
from bottle import route, run, template
|
||||
|
||||
|
||||
@route('/get_collection_count')
|
||||
def get_collection_count():
|
||||
coll_count = dict()
|
||||
for c in sorted(client.list_collections()):
|
||||
coll_count[c] = client.get_collection_stats(c)['row_count']
|
||||
return coll_count
|
||||
|
||||
|
||||
@route('/get_text_match')
|
||||
def get_matches():
|
||||
# %%
|
||||
valid_cameras = {'sidefeeder','ptz','railing','hummingbird','pond'}
|
||||
query = request.query.get('query','A large bird eating corn')
|
||||
cameras = request.query.get('cameras','sidefeeder')
|
||||
num_videos = int(request.query.get('num_videos',5))
|
||||
|
||||
cams = set(cameras.split(',')).intersection(valid_cameras)
|
||||
|
||||
cams = set(cameras.split(","))
|
||||
max_age = int(request.query.get('age',5));
|
||||
print({'Cameras':cams,'Max Age':max_age,'Query':query})
|
||||
max_date = datetime.now()
|
||||
min_date = max_date - timedelta(days=(max_age))
|
||||
min_date = max_date - timedelta(days=(max_age-1))
|
||||
days_step = (max_date- min_date).days
|
||||
day_strs = list()
|
||||
# %%
|
||||
for x in range(days_step):
|
||||
# pass
|
||||
day_strs.append( (min_date + timedelta(days=x)).strftime('%Y%m%d') )
|
||||
# if days_step > 0:
|
||||
# day_strs.append( (min_date + timedelta(days=0)).strftime('%Y%m%d') )
|
||||
|
||||
day_strs.append( max_date.strftime('%Y%m%d'))
|
||||
str_insert = ','.join([f'"{x}"'for x in day_strs])
|
||||
filter_string = 'date in [' + str_insert + ']'
|
||||
|
||||
if max_age == 0:
|
||||
filter_string = ''
|
||||
# %%
|
||||
vec_form = requests.get('http://192.168.1.242:53004/encode',params={'query':query}).json()['vector'][0]
|
||||
vec_search = np.asarray(vec_form).astype(np.float16)
|
||||
|
||||
|
||||
print(f'Doing query for {query}!')
|
||||
print('Filter string:',filter_string)
|
||||
all_results=list()
|
||||
try:
|
||||
error = ''
|
||||
@@ -73,11 +76,10 @@ def get_matches():
|
||||
all_results.extend(results[0])
|
||||
|
||||
except Exception as e:
|
||||
print(traceback.format_exc())
|
||||
error = traceback.format_exc()
|
||||
print(error)
|
||||
results = []
|
||||
|
||||
# %%
|
||||
def linux_to_win_path(form):
|
||||
form = form.replace('/srv','file://192.168.1.242/thebears/Videos/merged/')
|
||||
return form
|
||||
@@ -96,9 +98,8 @@ def get_matches():
|
||||
pload['winpath'] = linux_to_win_path(pload['filepath'])
|
||||
pload['frame'] = pload['frame_number']
|
||||
resul.append(pload)
|
||||
# %%
|
||||
|
||||
return_this = {'query':query,'num_videos':num_videos,'results':resul,'error':error}
|
||||
prettyprinter.pprint(return_this)
|
||||
return return_this
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
from doris_vector_search import DorisVectorClient, AuthOptions
|
||||
|
||||
auth = AuthOptions(
|
||||
host="192.168.1.242",
|
||||
query_port=9030,
|
||||
user="thebears",
|
||||
password="marybear",
|
||||
)
|
||||
|
||||
client = DorisVectorClient(database="nuggets", auth_options=auth)
|
||||
|
||||
tbl = client.open_table("video_embeddings")
|
||||
|
||||
query = [0.1] * 1152 # Example 128-dimensional vector
|
||||
|
||||
# SELECT id FROM sift_1M ORDER BY l2_distance_approximate(embedding, query) LIMIT 10;
|
||||
result = tbl.search(query, metric_type="inner_product").limit(10).select(["id"]).to_pandas()
|
||||
|
||||
print(result)
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
from pymilvus import MilvusClient, DataType
|
||||
|
||||
collection_name = "nuggets_{camera}_so400m_siglip2"
|
||||
client = MilvusClient(
|
||||
uri="http://localhost:19530"
|
||||
)
|
||||
# %%
|
||||
coll_count = dict()
|
||||
for c in sorted(client.list_collections()):
|
||||
print(c, client.get_load_state(c), client.get_collection_stats(c))
|
||||
|
||||
|
||||
# %%
|
||||
from pymilvus import utility
|
||||
# %%
|
||||
import requests
|
||||
query = 'A squirrel looking at the camera'
|
||||
vec_form = requests.get('http://192.168.1.242:53004/encode',params={'query':query}).json()['vector'][0]
|
||||
# %%
|
||||
from datetime import datetime, timedelta
|
||||
max_age = 5
|
||||
str_insert = ''
|
||||
days_step = 5
|
||||
max_date = datetime.now()
|
||||
min_date = max_date - timedelta(days=(max_age-1))
|
||||
days_step = (max_date- min_date).days
|
||||
day_strs = list()
|
||||
for x in range(days_step):
|
||||
day_strs.append( (min_date + timedelta(days=x)).strftime('%Y%m%d') )
|
||||
str_insert = ','.join([f'"{x}"'for x in day_strs])
|
||||
filter_string = 'date in [' + str_insert + ']'
|
||||
import numpy as np
|
||||
col_name = 'nuggets_railing_so400m_siglip2'
|
||||
vec_search = np.asarray(vec_form).astype(np.float16)
|
||||
results = client.search(collection_name = col_name,
|
||||
consistency_level="Eventually",
|
||||
data = [vec_search],
|
||||
filter=filter_string,
|
||||
search_params={'metric_type':'COSINE', 'params':{}},
|
||||
output_fields=['filepath','frame_number']
|
||||
)
|
||||
|
||||
|
||||
# %%
|
||||
for c in client.list_collections():
|
||||
# ff = client.describe_collection(collection_name = c)
|
||||
print(c)
|
||||
|
||||
|
||||
# %%
|
||||
|
||||
|
||||
col_target = 'nuggets_leopards1_so400m_siglip2'
|
||||
|
||||
import time
|
||||
# %%
|
||||
|
||||
|
||||
|
||||
print(client.get_collection_stats(c))
|
||||
|
||||
|
||||
# %%
|
||||
|
||||
# %%
|
||||
st = time.time()
|
||||
results = client.search(collection_name = col_target,data =[np.random.rand(1152).astype(np.float16)], limit = 100)
|
||||
print(len(results[0]), time.time() - st)
|
||||
Reference in New Issue
Block a user