tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.37k stars 1.92k forks source link

Model accessibility issues in China #1375

Closed wangtz closed 4 years ago

wangtz commented 5 years ago

Currently for pre-tained models, the weights and model graph is not shipped with NPM and needs to fetched at runtime from GCS. However GCS is not available in China or very slow which hurts user experiences.

Do we have a plan to make pre-trained models available in China? I would suggest to embed pre-trained weights in a fat NPM (probably new NPMs to avoid breaking existing use cases). But we could definitely find a place to host these content in China as well.

wangtz commented 5 years ago

@pyu10055 @nsthorat @dsmilkov @caisq @kangyizhang Any thoughts?

wangtz commented 5 years ago

@huan

huan commented 5 years ago

Yes, that's a problem and the developers will be very sad if it could not be solved.

For example, when we want to use the Google Chrome Puppeteer in China, what we expect the developer to do is a npm install puppeteer but it will fail eventually because after installing all the JS files from NPM server then it needs run a post-install script and wants to download the binary from the GCS storage server, which is not accessible in China because of the GFW.

There is a workaround for the puppeteer at here. I believe we should solve this kind of problem for the developers in China, for spreading the tfjs faster. (at least we should provide a workaround for installing tfjs-models)

caisq commented 5 years ago

+1 for solving this for developers in China. Most of our tfjs-models actually download weights from GCS at runtime. So I'm not sure if the puppeteer workaround @huan pointed out would work here.

chenqing commented 5 years ago

I think our company can provide the models storage and CDN services in China . may accelerate this.

huan commented 5 years ago

@chenqing That would be great if the npm.taobao.comnpm.taobao.org/mirrors could provide the CDN service for our tfjs models.

Do you know any stakeholders from npm.taobao.com who can make decisions on this issue? If you could introduce a key person for us, then we would be able to solve this issue easier.

chenqing commented 5 years ago

@huan I think what's your said is https://npm.taobao.org/mirrors . I have talked with the maintainer. He promised to support it. The next question is what and how to synchronize.

wangtz commented 5 years ago

That'll be awesome. Thanks Chenqing.

The first one coming out of my mind is probably rsync if that works on GCS?

wangtz commented 5 years ago

@chenglu

pyu10055 commented 5 years ago

Thanks @chenqing and @huan for the suggestion, as @caisq mentioned, our model npms do not have a post install script to download model files from gcs, and people can use jsdelivr directly on their pages, which will download the model files on the fly. Feels like the better way is to mirror GCS bucket, but not sure if that is possible.

chenglu commented 5 years ago

thanks @wangtz, I was wondering if we could try the feature of "mirror storage"--镜像存储 that alioss or qiniu provided for unblocking the tfjs-models bucket? e.g. http://tfjs.oss-cn-hongkong.aliyuncs.com/tfjs-models/weights/posenet/mobilenet_v1_075/MobilenetV1_Conv2d_8_pointwise_biases

chenqing commented 5 years ago

Thanks @chenqing and @huan for the suggestion, as @caisq mentioned, our model npms do not have a post install script to download model files from gcs, and people can use jsdelivr directly on their pages, which will download the model files on the fly. Feels like the better way is to mirror GCS bucket, but not sure if that is possible.

I think so .

chenqing commented 5 years ago

@wangtz @huan @caisq https://cnpmjs.org/mirrors/tfjs-models/ has sync ok. and will automatic synchronization when update.

I think may mention this in some parts of the document?

huan commented 5 years ago

@chenqing awesome, good job!

chenqing commented 5 years ago

I found when installing ttf-node npm will down libtensorflow from googleapis.com too. see https://github.com/tensorflow/tfjs-node/blob/master/scripts/install.js#L33 Unfortunately, this url can't be visited normally in China. upload libtensorflow to npm may be a solution. @caisq

franciscop commented 4 years ago

I came to ask where we can download those models to load them locally easier, but seeing this issue is very related I'll join here.

As a workaround what I did is opening the network developer tab, and copying the body of all the requests (one JSON, then N "shards"):

Screen Shot 2019-09-24 at 0 25 12

Then put them in your public folder as static file:

shards

Then you can load them using the option { modelUrl: '/objects/model.json' }. Does anyone know a better way? Seems like an easy way of downloading these models would help OP as well. I'm looking to improve this for a React Hook I made, use-tensorflow and currently I'm telling devs this way of loading those manually but it is painfully:

import React, { useRef } from "react";
import { useObjects } from "use-tensorflow";
import { Container, Box } from './components';

export default () => {
  const ref = useRef(null);
  const objects = useObjects(ref, { modelUrl: "/objects/model.json" });
  return (
    <Container>
      <img ref={ref} src="/living-room.jpg" />
      {objects.map(({ left, top, width, height, label, score }) => (
        ...
      ))}
    </Container>
  );
};
rthadur commented 4 years ago

Closing this due to lack of activity, feel to reopen. Thank you