1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| const loadImg =(src)=>{ return new Promise(resolve=>{ const img = document.createElement('img') img.crossOrigin = 'anonymous' img.src = src img.width = 224 img.height = 224 img.onload=()=>reslove(img) }) }
export const getInputs = async()=>{ const loadImgs = [] const labels = [] for(let i=0;i<30;i+=1){ ['android','apple','windows'].forEach(label=>{ const imgP = loadImg(`http://127.0.0.1:8080/brand/train/${label}-${index}.jpg`) loadImgs.push(imgP) labels.push([ label === 'android' ? 1 :0, label === 'apple' ? 1 :0, label === 'windows' ? 1 :0, ]) }) } const inputs = await Promise.all(loadImgs) return{ inputs, labels } }
|