Skip to content

Commit 563c0f5

Browse files
feat: Update background removal example
1 parent c00c850 commit 563c0f5

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

examples/misc/background-removal.php

+8-21
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,11 @@
88
use function Codewithkyrian\Transformers\Utils\{memoryPeak, memoryUsage, timeUsage};
99

1010
require_once './bootstrap.php';
11-
$modelConfig = ['model_type' => 'vit'];
12-
$processorConfig = [
13-
'do_normalize' => true,
14-
'do_pad' => false,
15-
'do_rescale' => true,
16-
'do_resize' => true,
17-
'image_mean' => [0.5, 0.5, 0.5],
18-
'feature_extractor_type' => "ImageFeatureExtractor",
19-
'image_std' => [1, 1, 1],
20-
'resample' => 2,
21-
'rescale_factor' => 0.00392156862745098,
22-
'size' => ['width' => 1024, 'height' => 1024],
23-
];
24-
25-
$model = AutoModel::fromPretrained(modelNameOrPath: 'briaai/RMBG-1.4', config: $modelConfig);
11+
12+
$model = AutoModel::fromPretrained(modelNameOrPath: 'briaai/RMBG-1.4');
2613
$processor = AutoProcessor::fromPretrained(modelNameOrPath: 'briaai/RMBG-1.4');
2714

28-
$url = __DIR__ . '/../images/multitask.png';
15+
$url = __DIR__ . '/../images/woman-w-bag.jpeg';
2916

3017
$image = Image::read($url);
3118

@@ -34,11 +21,11 @@
3421
['pixel_values' => $pixelValues] = $processor($image);
3522

3623
['output' => $output] = $model(['input' => $pixelValues]);
37-
24+
//
3825
$mask = Image::fromTensor($output[0]->multiply(255))->resize($image->width(), $image->height());
39-
26+
//
4027
$mask->save($fileName . '-mask.png');
41-
28+
//
4229
$maskedImage = $image->applyMask($mask);
43-
44-
$maskedImage->save($fileName . '-masked.png');
30+
//
31+
//$maskedImage->save($fileName . '-masked.png');

0 commit comments

Comments
 (0)