-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tf.loadModel Fails to load keras model #924
Comments
Can you open the browser's devtools and check the status of the responses to the weight requests. Those should show up as names such as "group1-shard1of2", etc. Make sure that the response status is 200 OK and that the content of the response is correct. We've seen various kinds of HTTP servers having trouble serving binary weight files like those correctly. |
@caisq I'm serving these files locally, and see that rather than 200, each file has a 304 'Not Modified' status. |
What kind of HTTP server are you using, @YajJackson ? |
I've been using parceljs. |
Is there anyway for me to test that the binaries are served properly besides tf.loadModel() failing? |
Couple of things:
|
@dsmilkov I can access the files directly from the browser. After clearing my cache, the 304s returned to 200 OK, so looks like we're good there. Turns out that the group1-shardxofy responses had |
+1 to Daniel's point that we should throw a more informative error message when the response code isn't 200 OK. |
@caisq I think 304 would also be acceptable. |
Good news! after switching from serving my files with parcel to webpack-dev-server, the content-type header was updated appropriately to Consider this snippet:
*where |
I can't say exactly what solved the issue I just mentioned, but after the following steps I was able to get that snippet to work properly:
¯_(ツ)_/¯ |
@YajJackson hello, when i use the tfjs loadfrozenmodel,i have the same problem: RangeError: byte length of Float32Array should be a multiple of 4, the statue is 200 and i alse use the parceljs, but also have the mistake, can you have any other suggestions? thanks |
I find it surprising that the weight shard files (group1*) have a size of
1.4 KB. They should be about 4 MB (except the last one), because that's the
default shard size. So it appears that they somehow got the wrong content.
…On Mon, Jan 14, 2019 at 3:39 AM sunny ***@***.***> wrote:
@YajJackson <https://github.com/YajJackson>
[image: image]
<https://user-images.githubusercontent.com/29625315/51102702-f0d1ac00-181a-11e9-9833-3a05642ee1c1.png>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#924 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQC5fk978I-jeTD6ra9ok-cfLcEaRRT7ks5vDEJDgaJpZM4YqSzn>
.
--
---
Shanqing Cai
Software Engineer
Google
cais@google.com
|
@YajJackson @caisq hello,i have similar problem,but the group* file is 1.4k,because of the parcel Can't serve static resources with no filename extension( parcel-bundler/parcel#1098 ),how can you success load the group* files? can you provide some suggestions, thanks. |
Can you the the following workaround:
* Rename the weight shard files so that they can have extension names,
e.g., group*.bin
* Modify the `weightsManifest` part of the JSON in the model.json file to
reflect the name changes in the weight shard files.
Feel free to file an issue at https://github.com/tensorflow/tfjs/issues for
us to add an extension name to the weight files.
…On Tue, Jan 15, 2019 at 8:27 PM sunny ***@***.***> wrote:
@YajJackson <https://github.com/YajJackson> @caisq
<https://github.com/caisq> hello,i have similar problem,but the group*
file is 1.4k,because of the parcel Can't serve static resources with no
filename extension( parcel-bundler/parcel#1098
<parcel-bundler/parcel#1098> ),how can you
success load the group* files? can you provide some suggestions, thanks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#924 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQC5fjZagMrxrqqXuFMko7rCZQWszDXoks5vDoATgaJpZM4YqSzn>
.
--
---
Shanqing Cai
Software Engineer
Google
cais@google.com
|
@caisq i rename the group* file as group*.bin and modify the key of "path" in the json, but failed, because the parcel use the require("weightsManifest.json") and return the file path is weightsManifest.(hash value).json, so the new path of group*.bin is group*.(hash value).bin。 |
Have you tried this parcel plugin?
https://www.npmjs.com/package/parcel-plugin-static-files-copy
It can copy files into the dist/ folder without adding the hash string to
the file name.
…On Tue, Jan 15, 2019 at 9:44 PM sunny ***@***.***> wrote:
@caisq <https://github.com/caisq> i rename the group* file as group*.bin
and modify the key of "path" in the json, but failed, because the parcel
use the require("weightsManifest.json") and return the file path is
weightsManifest.(hash value).json, so the new path of group*.bin is
group*.(hash value).bin。
[image: image]
<https://user-images.githubusercontent.com/29625315/51223155-b59abe80-197b-11e9-928a-ea1f7cab50e3.png>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#924 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQC5fvoUpRKCcr4M-WQARNuZPUBOAjyDks5vDpIdgaJpZM4YqSzn>
.
--
---
Shanqing Cai
Software Engineer
Google
cais@google.com
|
@caisq thanks,i'll try it. |
@caisq thanks for your suggestions, i solved the problem successfully,yesterday. |
Try to collect the solution in step-by-step tutorial:
After that, the issue should disappear! |
Same problem. What worked for me was
|
If you've experienced problems loading models in the latest release, we are working on a fix: #1188. It's related to the problem that we are strict about the We are going to revert the content type check. |
#1188 will be helpful, but I don't think it's the root of the problem. At least for me, the weights are an and here's the file, with Could it be that the issue is with misreading file type instead? |
Hi all, The fix just went in: tensorflow/tfjs-core#1532 and will be available in |
Worked like a charm for me thanks @mrmartin |
It just too complex for using! |
I have a similar error - I'm using express.js to send the json+bin files to react so that I can run inference in the browser itself. Here's the relevant Express.js code. The json+bin files are all in the same folder.
Here's how I'm loading this in React -
|
To get help from the community, check out our Google group.
TensorFlow.js version
0.13.5
Browser version
Version 70.0.3538.110 (Official Build) (64-bit)
Describe the problem or feature request
I can't load a keras model created by
tfjs.converters.save_keras_model
Code to reproduce the bug / link to feature request
Used this to create model.json
Attempt to load model here
result:
Any help would be greatly appreciated.
The text was updated successfully, but these errors were encountered: