bump
This commit is contained in:
+15
-18
@@ -1,31 +1,28 @@
|
|||||||
import open_clip
|
import open_clip
|
||||||
import torch
|
import torch
|
||||||
|
import functools
|
||||||
|
import onnxruntime as ort
|
||||||
|
|
||||||
do_load = True
|
model_name = 'ViT-SO400M-16-SigLIP2-512'
|
||||||
if do_load:
|
tokenizer = open_clip.get_tokenizer(model_name)
|
||||||
|
#onnx_path = "/home/thebears/Source/ml/clip_extract/text/ViT-SO400M-16-SigLIP2-512_text"
|
||||||
#model_name = 'hf-hub:timm/ViT-L-16-SigLIP2-512'
|
onnx_path = "/home/thebears/Source/ml/clip_extract/text/ViT-SO400M-16-SigLIP2-512_text_optimized"
|
||||||
# model, preprocess = open_clip.create_model_from_pretrained('hf-hub:timm/ViT-L-16-SigLIP2-512')
|
ort_sess = ort.InferenceSession(onnx_path)
|
||||||
|
|
||||||
|
|
||||||
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()
|
|
||||||
tokenizer = open_clip.get_tokenizer(model_name)
|
|
||||||
|
|
||||||
from bottle import route, run, template, request, debug
|
from bottle import route, run, template, request, debug
|
||||||
@route('/encode')
|
@route('/encode')
|
||||||
def get_matches():
|
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():
|
with torch.no_grad():
|
||||||
text_tokenized = tokenizer(query)
|
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}
|
return {'vector':vec}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
debug(True)
|
debug(True)
|
||||||
run(host='0.0.0.0', port=53004, server='bjoern')
|
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
|
from pymilvus import MilvusClient, DataType
|
||||||
|
import os
|
||||||
|
from tqdm import tqdm
|
||||||
client = MilvusClient(
|
client = MilvusClient(
|
||||||
uri="http://localhost:19530"
|
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]
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
|
c_collections = set(client.list_collections())
|
||||||
import os
|
for cam in tqdm(out):
|
||||||
out = os.listdir('/mergedfs/ftp/')
|
c_col_name = f"nuggets_{cam}_so400m_siglip2"
|
||||||
|
if c_col_name in c_collections:
|
||||||
# %%
|
print(f"Skipping {c_col_name}")
|
||||||
for cam in out:
|
continue
|
||||||
|
else:
|
||||||
|
print(f"Creating {c_col_name}")
|
||||||
schema = MilvusClient.create_schema(
|
schema = MilvusClient.create_schema(
|
||||||
auto_id=False,
|
auto_id=False,
|
||||||
nenable_dynamic_field=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="filepath", datatype=DataType.VARCHAR, max_length=128)
|
||||||
schema.add_field(field_name="frame_number", datatype=DataType.INT32)
|
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="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()
|
index_params = client.prepare_index_params()
|
||||||
@@ -40,7 +49,7 @@ for cam in out:
|
|||||||
|
|
||||||
index_params.add_index(
|
index_params.add_index(
|
||||||
field_name="so400m",
|
field_name="so400m",
|
||||||
index_type="IVF_SQ8",
|
index_type="DISKANN",
|
||||||
metric_type="COSINE",
|
metric_type="COSINE",
|
||||||
params={'nlist':128})
|
params={'nlist':128})
|
||||||
|
|
||||||
@@ -49,16 +58,13 @@ for cam in out:
|
|||||||
index_type='Trie')
|
index_type='Trie')
|
||||||
|
|
||||||
client.create_collection(
|
client.create_collection(
|
||||||
collection_name=f"nuggets_{cam}_so400m_siglip2",
|
collection_name=c_col_name,
|
||||||
schema=schema,
|
schema=schema,
|
||||||
index_params=index_params
|
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")
|
#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()
|
to_put = list()
|
||||||
for root, dirs, files in os.walk(root_path):
|
for root, dirs, files in os.walk(root_path):
|
||||||
for x in files:
|
for x in files:
|
||||||
|
|||||||
+24
-23
@@ -8,51 +8,54 @@ import traceback
|
|||||||
from bottle import route, run, template, request, debug
|
from bottle import route, run, template, request, debug
|
||||||
import time
|
import time
|
||||||
import prettyprinter
|
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(
|
client = MilvusClient(
|
||||||
uri="http://localhost:19530"
|
uri="http://localhost:19530"
|
||||||
)
|
)
|
||||||
# %%
|
|
||||||
|
|
||||||
|
|
||||||
from bottle import route, run, template
|
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')
|
@route('/get_text_match')
|
||||||
def get_matches():
|
def get_matches():
|
||||||
# %%
|
|
||||||
valid_cameras = {'sidefeeder','ptz','railing','hummingbird','pond'}
|
|
||||||
query = request.query.get('query','A large bird eating corn')
|
query = request.query.get('query','A large bird eating corn')
|
||||||
cameras = request.query.get('cameras','sidefeeder')
|
cameras = request.query.get('cameras','sidefeeder')
|
||||||
num_videos = int(request.query.get('num_videos',5))
|
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));
|
max_age = int(request.query.get('age',5));
|
||||||
print({'Cameras':cams,'Max Age':max_age,'Query':query})
|
|
||||||
max_date = datetime.now()
|
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
|
days_step = (max_date- min_date).days
|
||||||
day_strs = list()
|
day_strs = list()
|
||||||
# %%
|
|
||||||
for x in range(days_step):
|
for x in range(days_step):
|
||||||
|
# pass
|
||||||
day_strs.append( (min_date + timedelta(days=x)).strftime('%Y%m%d') )
|
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])
|
str_insert = ','.join([f'"{x}"'for x in day_strs])
|
||||||
filter_string = 'date in [' + str_insert + ']'
|
filter_string = 'date in [' + str_insert + ']'
|
||||||
|
|
||||||
if max_age == 0:
|
if max_age == 0:
|
||||||
filter_string = ''
|
filter_string = ''
|
||||||
# %%
|
|
||||||
vec_form = requests.get('http://192.168.1.242:53004/encode',params={'query':query}).json()['vector'][0]
|
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)
|
vec_search = np.asarray(vec_form).astype(np.float16)
|
||||||
|
print('Filter string:',filter_string)
|
||||||
|
|
||||||
print(f'Doing query for {query}!')
|
|
||||||
all_results=list()
|
all_results=list()
|
||||||
try:
|
try:
|
||||||
error = ''
|
error = ''
|
||||||
@@ -73,11 +76,10 @@ def get_matches():
|
|||||||
all_results.extend(results[0])
|
all_results.extend(results[0])
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(traceback.format_exc())
|
|
||||||
error = traceback.format_exc()
|
error = traceback.format_exc()
|
||||||
|
print(error)
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
# %%
|
|
||||||
def linux_to_win_path(form):
|
def linux_to_win_path(form):
|
||||||
form = form.replace('/srv','file://192.168.1.242/thebears/Videos/merged/')
|
form = form.replace('/srv','file://192.168.1.242/thebears/Videos/merged/')
|
||||||
return form
|
return form
|
||||||
@@ -96,9 +98,8 @@ def get_matches():
|
|||||||
pload['winpath'] = linux_to_win_path(pload['filepath'])
|
pload['winpath'] = linux_to_win_path(pload['filepath'])
|
||||||
pload['frame'] = pload['frame_number']
|
pload['frame'] = pload['frame_number']
|
||||||
resul.append(pload)
|
resul.append(pload)
|
||||||
# %%
|
|
||||||
return_this = {'query':query,'num_videos':num_videos,'results':resul,'error':error}
|
return_this = {'query':query,'num_videos':num_videos,'results':resul,'error':error}
|
||||||
prettyprinter.pprint(return_this)
|
|
||||||
return 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