@@ -26,9 +26,7 @@ const imageToUint8ClampedArray = async (image: HTMLImageElement, dims: [number,
2626} ;
2727
2828const loadTensorFromHTMLImage = async ( image : HTMLImageElement , dims : [ number , number ] ) => {
29- console . log ( 'prepare to get arr' ) ;
3029 const arr = await imageToUint8ClampedArray ( image , dims ) ;
31- console . log ( 'got arr, prepare to get tensor' ) ;
3230 return imageDataToTensor ( arr ) ;
3331}
3432
@@ -37,7 +35,6 @@ const imageDataToTensor = async ({
3735 width,
3836 height,
3937} : IImageData ) => {
40- console . log ( 'prepare to get tensor' , width , height ) ;
4138 return tf . tensor3d ( Array . from ( data ) , [ width , height , 4 ] ) ;
4239} ;
4340
@@ -49,23 +46,19 @@ interface IImageData {
4946
5047export interface ImageError {
5148 image : any ;
52- error : Error ,
49+ error : Error ;
50+ index : number ;
5351}
5452
5553const getTranslatedImageAsTensor = async ( image : tf . Tensor3D | IImageData | HTMLImageElement | string , dims : [ number , number ] ) => {
5654 if ( image instanceof tf . tensor3d ) {
57- console . log ( 'tensor' ) ;
5855 return image ;
5956 } else if ( typeof image === 'string' ) {
60- console . log ( 'strgin' ) ;
6157 const loadedImage = await loadImage ( image ) ;
62- console . log ( 'got loaded image' ) ;
6358 return await loadTensorFromHTMLImage ( loadedImage , dims ) ;
6459 } else if ( image instanceof HTMLImageElement ) {
65- console . log ( 'html image el' ) ;
6660 return await loadTensorFromHTMLImage ( image , dims ) ;
6761 } else if ( image instanceof ImageData ) {
68- console . log ( 'image data' ) ;
6962 return await imageDataToTensor ( image ) ;
7063 }
7164
@@ -78,23 +71,20 @@ const translateImages = async (origImages: Array<tf.Tensor3D | IImageData | HTML
7871 const labels = [ ] ;
7972
8073 for ( let i = 0 ; i < origImages . length ; i ++ ) {
81- console . log ( 'translating' , i ) ;
8274 const origImage = origImages [ i ] ;
8375 try {
84- console . log ( 'prepare to get' ) ;
8576 const image = await getTranslatedImageAsTensor ( origImage , dims ) ;
86- console . log ( 'gotten' ) ;
8777 // else, it is already a tensor
8878
8979 images . push ( image ) ;
9080 if ( origLabels ) {
9181 labels . push ( origLabels [ i ] ) ;
9282 }
9383 } catch ( error ) {
94- console . log ( 'error for' , i ) ;
9584 errors . push ( {
9685 image : origImage ,
9786 error,
87+ index : i ,
9888 } ) ;
9989 }
10090 }
0 commit comments