chore: import upstream snapshot with attribution
build / build (macos-latest) (push) Has been cancelled
build / build (ubuntu-latest) (push) Has been cancelled
build / build (windows-latest) (push) Has been cancelled
minimal / deploy (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:38:00 +08:00
commit 3a7c47b2a6
623 changed files with 133790 additions and 0 deletions
@@ -0,0 +1,36 @@
"""
Caption module tests
"""
import unittest
from PIL import Image
from transformers import AutoModelForImageTextToText, AutoImageProcessor, AutoTokenizer
from txtai.pipeline import Caption
# pylint: disable=C0411
from utils import Utils
class TestCaption(unittest.TestCase):
"""
Caption tests.
"""
def testCaption(self):
"""
Test captions
"""
caption = Caption()
self.assertEqual(caption(Image.open(Utils.PATH + "/books.jpg")), "a book shelf filled with books and a stack of books")
# Load passing models directly
path = "ydshieh/vit-gpt2-coco-en"
model = AutoModelForImageTextToText.from_pretrained(path)
tokenizer = AutoTokenizer.from_pretrained(path)
processor = AutoImageProcessor.from_pretrained(path)
caption = Caption((model, tokenizer, processor))
self.assertEqual(caption(Image.open(Utils.PATH + "/books.jpg")), "a book shelf filled with books and a stack of books")
@@ -0,0 +1,74 @@
"""
ImageHash module tests
"""
import unittest
from PIL import Image
from txtai.pipeline import ImageHash
# pylint: disable=C0411
from utils import Utils
class TestImageHash(unittest.TestCase):
"""
ImageHash tests.
"""
@classmethod
def setUpClass(cls):
"""
Caches an image to hash
"""
cls.image = Image.open(Utils.PATH + "/books.jpg")
def testArray(self):
"""
Test numpy return type
"""
ihash = ImageHash(strings=False)
self.assertEqual(ihash(self.image).shape, (64,))
def testAverage(self):
"""
Test average hash
"""
ihash = ImageHash("average")
self.assertIn(ihash(self.image), ["0859dd04bfbfbf00", "0859dd04ffbfbf00"])
def testColor(self):
"""
Test color hash
"""
ihash = ImageHash("color")
self.assertIn(ihash(self.image), ["1ffffe02000e000c0e0000070000", "1ff8fe03000e00070e0000070000"])
def testDifference(self):
"""
Test difference hash
"""
ihash = ImageHash("difference")
self.assertEqual(ihash(self.image), "d291996d6969686a")
def testPerceptual(self):
"""
Test perceptual hash
"""
ihash = ImageHash("perceptual")
self.assertEqual(ihash(self.image), "8be8418577b331b9")
def testWavelet(self):
"""
Test wavelet hash
"""
ihash = ImageHash("wavelet")
self.assertEqual(ihash(Utils.PATH + "/books.jpg"), "68015d85bfbf3f00")
@@ -0,0 +1,40 @@
"""
Objects module tests
"""
import unittest
from txtai.pipeline import Objects
# pylint: disable=C0411
from utils import Utils
class TestObjects(unittest.TestCase):
"""
Object detection tests.
"""
def testClassification(self):
"""
Test object detection using an image classification model
"""
objects = Objects(classification=True, threshold=0.3)
self.assertEqual(objects(Utils.PATH + "/books.jpg")[0][0], "library")
def testDetection(self):
"""
Test object detection using an object detection model
"""
objects = Objects()
self.assertEqual(objects(Utils.PATH + "/books.jpg")[0][0], "book")
def testFlatten(self):
"""
Test object detection using an object detection model, flatten to return only objects
"""
objects = Objects()
self.assertEqual(objects(Utils.PATH + "/books.jpg", flatten=True)[0], "book")