'Tensorflow mobilenet use models offline
Im using mobilenet from tensorflow and are trying to load the models offline.
The model loads here:
tf.loadModel(this.path)]
My first approach was to simply download the model.json and point to that file instead of the full url in my code as follows:
// this.path = 'https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_1.0_224/model.json';
this.path = "./model.json";
But then I am getting the following error:

GET https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_1.0_224/group37-shard1of1 net::ERR_INTERNET_DISCONNECTED
weights_loader.js:47
How do I download and point correctly to the weights for use it offline?
UPDATE I now just downloaded every shard manually by using the link in the errormessage.
https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_1.0_224/group1-shard1of1 https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_1.0_224/group1-shard1of1 https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_1.0_224/group1-shard1of1 and so on up to https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v1_1.0_224/group55-shard1of1
Now the groups loads correctly:

but I am getting a new errormessage:
Error: Based on the provided shape, [1,1,1024,1000], and dtype float32, the tensor should have 1024000 values but has 410072
Solution 1:[1]
when you download model.json you can see group1-shard1of2 and group1-shard2of2 text in that json
change these text to group1-shard1of2.txt and group1-shard2of2.txt
and put these files in your server location
and that will works well
Solution 2:[2]
If you have tensorflow installed the MobileNet and MobileNet version 2 models are available as shown below. Documentation is [here.][1]. For original version you can get the weights for the model trained on the imagenet data set for image size 224 X 224 with the code below. There are four sets of pre-trained weights available for image sizes 224, 192,160,128 so select the one you want. Below I selected the weights for the 224 X 224 image size. The variable weights will contain the pre-trained weights.
image_size=224
mobile = tf.keras.applications.mobilenet.MobileNet( include_top=True,
input_shape=(image_size,image_size,3), weights='imagenet',alpha=1, depth_multiplier=1, dropout=.1)
model = Model(inputs=mobile.input, outputs=mobile.output)
model.compile(Adamax(lr=.001), loss='categorical_crossentropy', metrics=['accuracy'])
weights=model.get_weights()
[1]: https://keras.io/api/applications/mobilenet/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jaesang Song |
| Solution 2 |
