swimauger / image-classifier

📸 Machine Learning Image Classifier for NodeJS using KNN
MIT License
9 stars 1 forks source link

[Mac M1] Error on npm i #14

Open GitHelge opened 2 years ago

GitHelge commented 2 years ago

Hey there, currently, I get an error on installing this library with npm i

If I try with npm i --legacy-peer-deps, it does run through, but im not sure if this is the solution.

Does anyone have an idea how this could be solved?

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: undefined@undefined
npm ERR! Found: @tensorflow/tfjs-core@1.7.4
npm ERR! node_modules/@tensorflow/tfjs-core
npm ERR!   peer @tensorflow/tfjs-core@"^1.2.1" from @tensorflow-models/knn-classifier@1.2.2
npm ERR!   node_modules/@tensorflow-models/knn-classifier
npm ERR!     @tensorflow-models/knn-classifier@"^1.2.2" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! @tensorflow-models/mobilenet@"^2.0.4" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @tensorflow/tfjs-core@3.12.0
npm ERR! node_modules/@tensorflow/tfjs-core
npm ERR!   peer @tensorflow/tfjs-core@"^3.1.0" from @tensorflow-models/mobilenet@2.1.0
npm ERR!   node_modules/@tensorflow-models/mobilenet
npm ERR!     @tensorflow-models/mobilenet@"^2.0.4" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

My package.json:

{
  "dependencies": {
    "@tensorflow-models/knn-classifier": "^1.2.2",
    "@tensorflow-models/mobilenet": "^2.0.4",
    "@tensorflow/tfjs": "^2.0.1",
    "@tensorflow/tfjs-backend-wasm": "^3.3.0",
    "@tensorflow/tfjs-node": "^2.0.1",
    "tensorset": "^1.2.6"
  }
}

System: Mac M1 Big Sur 11.6

Node version: v14.17.6, v16.13.1 (current) npm version: 8.0.0, 8.1.2 (current)

swimauger commented 2 years ago

Hey @GitHelge,

Things may have recently changed and I will investigate, but I believe TensorflowJS was not working with the new M1 MacBooks when I tried it on mine... While I investigate, maybe you could consider trying to Dockerize the project your working on to run it.

GitHelge commented 2 years ago

Im currently working on the dockerization, but I cannot get it to run.

I used npm i --legacy-peer-deps

Dockerfile:

FROM node:16.13.1-alpine3.12

WORKDIR /app
COPY package.json ./

# Stuff for another library:
RUN apk add --update --no-cache \
    make \
    g++ \
    jpeg-dev \
    cairo-dev \
    giflib-dev \
    pango-dev \
    libtool \
    autoconf \
    automake \
    libc6-compat

# RUN npm install
COPY . ./
RUN npm install --legacy-peer-deps

Installation fails with:

#10 10.74 npm ERR! code 1
#10 10.74 npm ERR! path /app/node_modules/@tensorflow/tfjs-node
#10 10.75 npm ERR! command failed
#10 10.75 npm ERR! command sh -c node scripts/install.js
#10 10.75 npm ERR! CPU-linux-3.12.0.tar.gz
#10 10.75 npm ERR! * Downloading libtensorflow
#10 10.75 npm ERR! /app/node_modules/@tensorflow/tfjs-node/scripts/install.js:106
#10 10.75 npm ERR!     throw new Error(`Unsupported system: ${libType}-${platform}-${os.arch()}`);
#10 10.75 npm ERR!           ^
#10 10.75 npm ERR! 
#10 10.75 npm ERR! Error: Unsupported system: cpu-linux-arm64
#10 10.75 npm ERR!     at getPlatformLibtensorflowUri (/app/node_modules/@tensorflow/tfjs-node/scripts/install.js:106:11)
#10 10.75 npm ERR!     at downloadLibtensorflow (/app/node_modules/@tensorflow/tfjs-node/scripts/install.js:139:15)
#10 10.75 npm ERR!     at async run (/app/node_modules/@tensorflow/tfjs-node/scripts/install.js:208:5)
#10 10.76 
#10 10.76 npm ERR! A complete log of this run can be found in:
#10 10.76 npm ERR!     /root/.npm/_logs/2021-12-29T22_14_19_027Z-debug.log

An update: tfjs-node recently merged a PR with an update for running on cpu-darwin-arm64 but not for cpu-linux-arm64. I tried with a simulated amd64 build but ran into different issues. 😅