Skip to content

Commit 2a0db6d

Browse files
Standardize setting image driver
1 parent 677f822 commit 2a0db6d

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/Pipelines/ZeroShotObjectDetectionPipeline.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ public function __invoke(array|string $inputs, ...$args): array
6969
$toReturn = [];
7070
foreach ($preparedImages as $i => $image) {
7171
$imageSize = $percentage ? null : [[$image->height(), $image->width()]];
72-
$pixelValues = $modelInputs['pixel_values'][$i];
73-
74-
$pixelValues = Tensor::fromArray($pixelValues)->unsqueeze(0);
72+
$pixelValues = $modelInputs['pixel_values'][$i]->unsqueeze(0);
7573

7674
// Run model with both text and pixel inputs
7775
/** @var ObjectDetectionOutput $output */

src/Transformers.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ public static function setup(): static
6969

7070
public function apply(): void
7171
{
72-
Image::$imagine = match (self::$imageDriver) {
73-
ImageDriver::IMAGICK => new \Imagine\Imagick\Imagine(),
74-
ImageDriver::GD => new \Imagine\GD\Imagine(),
75-
ImageDriver::VIPS => new \Imagine\Vips\Imagine(),
76-
};
72+
Image::setDriver(self::$imageDriver);
7773
}
7874

7975
/**

src/Utils/Image.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ public function __construct(public ImageInterface $image, public int $channels =
8282
}
8383
}
8484

85+
public static function setDriver(ImageDriver $imageDriver) : void
86+
{
87+
self::$imagine = match ($imageDriver) {
88+
ImageDriver::IMAGICK => new \Imagine\Imagick\Imagine(),
89+
ImageDriver::GD => new \Imagine\GD\Imagine(),
90+
ImageDriver::VIPS => new \Imagine\Vips\Imagine(),
91+
};
92+
}
93+
8594
public static function read(string $input, array $options = []): static
8695
{
8796
$image = self::$imagine->open($input, $options);

0 commit comments

Comments
 (0)