Files
Geniusia_v2/rpa_vision_v3/examples/test_openclip_owl_integration.py
2026-03-05 00:20:25 +01:00

210 lines
7.2 KiB
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
t()
s !")
prinlee VRAIS modèntenant dutilise maion V3 RPA Visisystèmet("🎉 Le rint()
princision")
peilleure préur mnCV poète OpeCompl(" -
printUI")d'éléments zero-shot - Détection(" printetector")
ns UIDnctionnel dat foégré e OWL-v2 int
print(")
print()toires !"éaalecteurs lus de vint(" - P
praires)")ings similbeddres → emaimilages sivérifiée (imnce - Cohérerint(" ")
prme L2 = 1)(nosés gs normaliEmbeddinnt(" - r")
priildeeEmbeddingBus Stattionnel dant fonc eintégréCLIP int("✅ Openint()
pr * 70)
pr"="")
print(Testsumé des " Rés)
print(" * 70t("=rin
p====
================================================================= =======sumé
#====
# Ré====================================================================
# ====t()
prin(1)
ys.exit()
sprint_excback.
trace traceback importe}")
EC Test 2: {nt(f"❌ ÉCHpri:
eption as et Excré")
excepgno(" Test i
print)0"=4.35.mers>ll transforpip instan: tiollaInstaprint(" : {e}")
n disponible-v2 not(f"⚠️ OWLe:
prinrror as ImportE
exceptement")e correcttionn-v2 foncÉUSSI: OWL Test 2 Rt("\nrin
p elle")
fonctionntion OWL-v2 t("✓ Détec prine:
els")
?) trop élevé(seuil détecté élémentcun Au print("⚠️ s) == 0:
detectionn(owl_ le if
ox']}") @ {det['bb3f}ce']:.iden{det['conf}: abel']{i}. {det['lt(f" prin
ons, 1):etectiate(owl_der det in enumfor i,")
s:nt élémeections)}len(owl_detcté {v2 a déte"✓ OWL-(f print
g)
(test_imentstect_ui_elemr.dector.owl_detens = detectowl_detectio
o-v2...") OWLion avecétectst de drint("\nTe pWL
avec Oon directeectiTest de dét #
")
tectorsé dans UIDeialiinit OWL-v2 "✓ print( else:
oré")
Test ign(" print")
.0354.mers>=forstall transpip in: ationtallt(" Insinpr
nquant?)")masformers ible (trant pas dispon OWL-v2 n'es⚠ print(" None:
ctor is wl_deteector.o if detisé
alL est initiue OWier q Vérif
#ig)
(config=conftectorDeUIetector = d
)
=0.05hresholdnce_t owl_confide test
cever VLM pour # Désaction=False,ficatilm_classi use_v on=True,
ectil_det use_ow ig(
ctionConffig = Dete")
conec OWL-v2...avUIDetector tion du Créat("\nv2
prin avec OWL-urteréer détec
# C
h}")t_pat {tes créée:mage de testrint(f" I ph)
patsave(test_mg.t_ites
.png"ionl_integrat"test_ownt / file__).pareath(__h = P test_patr
Sauvegarde
# ont)
), font=f555, 2=(255, 25ill fubmit","S15), xt((150, 1aw.te
dr()
load_defaultgeFont.nt = Ima fo
except:f", 16)
Sans.ttejavu/DejaVupe/dfonts/truetyr/share/etype("/ust.trumageFon = I font
try:xte
jouter te # A
, width=2)50, 50)line=(50, 5), out, 150, 2500, fill=(1(button_rectectangleraw.r d150]
, 00, 2500, 1n_rect = [10tto bu
nbouto un iner# Dess
)
w(test_imgageDraw.Dra draw = Im , 240))
(240, 240lor= co400, 300),('RGB', ( Image.new_img =test")
de test...ne imageion d'u("Créat printouton
un b test avecimage der une # Créeor
OwlDetectort detector impction.owl_ore.detem c fronConfig
Detectioector, t UIDetr imporetectoi_dection.ucore.det from ry:
t-" * 70)
int("r")
pr UIDetectov2 dans 2: OWL-int("Test===
pr===================================================================or
# ======ctdans UIDeteL-v2 st 2: OW# Te========
==================================================================nt()
# ==pri(1)
sys.exit nt_exc()
eback.prik
traccebacra import t 1: {e}")
HEC Test ÉCf"❌int( pras e:
xception
except E
ement")ectorrctionne conIP f OpenCL1 RÉUSSI:est "\n T
print(
")ngs vérifiéebeddince des emohéret(" C prin
(1)
s.exitsy ")
imilaritéplus de s avoir evraientes dmilairsi: Images "❌ ÉCHEC print(sim_13:
= if sim_12 <
}")
sim_13:.4fouge-bleu: {Similarité r" rint(f
p_12:.4f}")uge: {sime-roroug Similarité int(f" pr
ntes
différe Images 3) #ot(emb1, embnp.d13 = sim_
ess similair Image) #, emb2ot(emb1= np.dim_12 nus
s cosiarité# Simil
3)
image_image(.embedderclip_embedbuilder. emb3 = age2)
bed_image(imedder.em.clip_emb= builder2 1)
embimage(imagembed_r.elip_embeddebuilder.c= emb1
# Bleu255)) 0, =(0, 224), color, ', (224GBw('R3 = Image.ne imageire
mila Rouge si10, 10)) #=(255, 224), color', (224,'RGBe.new(age2 = Imag imuge
# Ro0, 0)) , 55), color=(2(224, 224('RGB', = Image.new
image1nce...") cohéredet("\nTest in prilaires
dings sim embedavoirivent es doairimages similcohérence: # Test de
")
m:.4f}) {text_norrme =ormalisé (note nedding texmb"✓ Ent(f
pri t(1)
xi sys.e f}")
norm:.4= {text_xte edding te l'embrme de ÉCHEC: Not(f"❌ prin 1.01):
< < text_norm.99 ot (0
if n g)
ext_embeddinlg.norm(tp.linaext_norm = n tton")
("butmbed_text_embedder.eder.clipdding = built_embe texe...")
ing de text'embeddst d"\nTe( printe texte
dd'embedding
# Test
4f})"){norm:.é (norme = ormalisng nddi" Emberint(f
pxit(1) sys.e)
normalisé"n léatoire nocteur aà un ve ressemble Cela" print(1.0)")
ndu ~atte4f} ( {norm:.edding =emborme de l'"❌ ÉCHEC: Nrint(f
p< 1.01):m 99 < nort (0. if no
g)bedding.norm(emm = np.linal 1)
nore L2 =norms (séormalisont nP dings CLImbed # Les e normale
distributione t unatoires onléteurs a # Les vectoire
vecteur aléa PAS un est que ce n'# Vérifier
_image)
stimage(tebed__embedder.emr.clipilde bu embedding =
, 150, 200)) color=(100, 224),24RGB', (2ge.new(' Ima_image =")
testd'image...d'embedding "\nTest nt(
priimageng d'd'embeddist
# Te ")
dderCLIPEmbelise age utiim Embedder print("
(1)
sys.exit
Embedder")st pas CLIPage n'er imembedde ÉCHEC: L'nt(" pri:
der)LIPEmbedimage"), C"t(embedders.gelder.tance(buif not isins iCLIP
tilisent mbedders u les erifier que
# Vé")
lderbeddingBuidans StateEmisé initialOpenCLIP t(" prin1)
sys.exit(")
initialisés LIP n'est paCHEC: OpenC print("❌ É
s None:der i.clip_embed buildersé
ifali initiIP estifier que CL
# VérTrue)
lip=uilder(use_cddingBmbeateE Stlder =ui b)
enCLIP..."er avec OpddingBuild StateEmbeéation du print("CrOpenCLIP
ec builder avr un # Crée
dder
IPEmber import CL_embeddeclipding..embed from corelder
beddingBuiport StateEmimbuilder g_ddinate_embeing.stre.embeddfrom co:
try * 70)"-"")
print(erdingBuildteEmbedtaans SP dnCLIt 1: Opent("Tes
pri===
====================================================================== ===Builder
#eEmbeddingans StatenCLIP dest 1: Op# T===
=====================================================================
# ====)
print()"=" * 70")
print(LIP + OWL-v2enCOpn 'IntégratioTest dt("
prin"=" * 70)
print(umpy as npt npor
imageFontraw, Im ImageDrt Image,mpo
from PIL int))
.parent.pareth(__file__)str(Pa.insert(0, thsys.pa au path
arentertoire péper le r Ajout
#Pathib import om pathlport sys
fr"
im
""aléatoires.e vecteurs au lieu dutilisés t modèles sone les vrais
Vérifie qu + OWL-v2
n OpenCLIPtégratio d'In
Test"""ython3
in/env p#!/usr/b