@@ -75,6 +75,40 @@ output = await depth_estimator(as_url("/tmp/bread_small.png"))
75
75
76
76
await pyodide . runPythonAsync ( `
77
77
output["depth"].save('/tmp/depth.png')
78
+ ` ) ;
79
+ const depthImage : Uint8Array = pyodide . FS . readFile ( "/tmp/depth.png" , { encoding : "binary" } ) ;
80
+ // TODO: How to assert the depth image? Image snapshot is not available in the browser env.
81
+ } )
82
+
83
+ test ( "depth-estimation with a RawImage input" , async ( ) => {
84
+ await pyodide . runPythonAsync ( `
85
+ from transformers_js_py import import_transformers_js, as_url
86
+
87
+ transformers = await import_transformers_js()
88
+
89
+ pipeline = transformers.pipeline
90
+ RawImage = transformers.RawImage
91
+
92
+ depth_estimator = await pipeline('depth-estimation', 'Xenova/depth-anything-small-hf');
93
+
94
+ image = await RawImage.fromURL('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/db8bd36/bread_small.png')
95
+
96
+ output = await depth_estimator(image)
97
+ ` ) ;
98
+ const outputMap = await pyodide . globals . get ( "output" ) . toJs ( ) // Python's dict to JS's Map
99
+ const output = Object . fromEntries ( outputMap ) ;
100
+
101
+ const depth = output . depth . toJs ( ) ;
102
+ const predictedDepth = output . predicted_depth . toJs ( ) ;
103
+
104
+ // API reference: https://huggingface.co/Xenova/depth-anything-small-hf
105
+ expect ( depth . width ) . toBe ( 640 )
106
+ expect ( depth . height ) . toBe ( 424 )
107
+ expect ( depth . channels ) . toBe ( 1 )
108
+ expect ( predictedDepth ) . toBeDefined ( )
109
+
110
+ await pyodide . runPythonAsync ( `
111
+ output["depth"].save('/tmp/depth.png')
78
112
` ) ;
79
113
const depthImage : Uint8Array = pyodide . FS . readFile ( "/tmp/depth.png" , { encoding : "binary" } ) ;
80
114
// TODO: How to assert the depth image? Image snapshot is not available in the browser env.
0 commit comments