0

I am trying to make sure that the classification, training process and the model is hidden while used in browser. I have found that wasm is kind of binary format for web browser to execute. Can I use wasm?

  • Is there a way in tensorflow or in js to hide my training or classification algorithm and pre-trained model?

  • Is there any other framework supporting it?

Navid
  • 53
  • 10
  • https://stackoverflow.com/help/how-to-ask – Kaveh Vahedipour Apr 26 '18 at 12:18
  • 3
    Possible duplicate of [How private is my code in WebAssembly?](https://stackoverflow.com/questions/49538827/how-private-is-my-code-in-webassembly) – ColinE Apr 26 '18 at 12:19
  • I need to make my model private too.. again I want to train it on user browser and also want to do classification on users browser... how am I going to import my model and keep it hidden? – Navid Apr 26 '18 at 12:28
  • Colin webassembly only support c++ not js... and tensorflow.js is a whole new thing I don't think its duplicate... And I couldn't find any examples on regarding this issue – Navid Apr 26 '18 at 12:32
  • It's probably a duplicate, because the answer is the same and the question is nearly the same. – Thomas Sablik Apr 26 '18 at 12:59
  • webassembly doesn't support js because it doesn't have any garbage collection process... again webassembly can't hide a model as far as I know.. tell me how is it duplicate? – Navid Apr 26 '18 at 13:02
  • You are asking how to hide your js code. The answer is: It's not possible – Thomas Sablik Apr 26 '18 at 13:04
  • The answer is applicable for every programming language. C++ is an example – Thomas Sablik Apr 26 '18 at 13:05
  • okay then how to hide the trained model in wasm ? – Navid Apr 26 '18 at 13:05
  • Since your model will be read by your progam and the user can intercept the data from your program (js is very user friendly) I think you can't either. – Thomas Sablik Apr 26 '18 at 13:09
  • are you saying that it is applicable for python too? – Navid Apr 26 '18 at 13:09
  • It's independent of the programming language. Your code will be compiled into wasm. There are possibilities to reconstruct your wasm. The wasm is independend of the programming language so the reconstruction is. – Thomas Sablik Apr 26 '18 at 13:11
  • According to http://webassembly.org/docs/faq/ " As WebAssembly evolves it will support more languages than C/C++, and we hope that other compilers will support it as well, even for the C/C++ language, for example GCC. " – Navid Apr 26 '18 at 13:18
  • Sir you missing one thing again and again webassembly does not have any garbage collection process so running python is not a option for now at least. If they have any we could just run js in webassembly. – Navid Apr 26 '18 at 13:23
  • @navid: as one of the designers and implementors of WebAssembly I guarantee you that your question is a duplicate. You code is not private on the web because it runs on the user's machine. That user can get the code, and all you can do is try to obfuscate it. It was a non-goal of WebAssembly to make it "hidden" because that's how the web works. – JF Bastien Apr 26 '18 at 15:50
  • @JF Bastien : thank you. sir can you explain one more thing? that is what happens the code inside EM_ASM function? I mean is that code get compiled or interpreted at runtime.. If compiled then if that runs faster or slower than native interpreted js in browser? – Navid Apr 26 '18 at 16:32
  • 1
    @navid that's a pretty big question for a small comment section. I suggest reading up on WebAssembly some more, and asking more pointed questions outside the comments. – JF Bastien Apr 26 '18 at 16:47
  • okay sir I am posting it outside – Navid Apr 26 '18 at 16:49
  • @JFBastien sir can you reply this question https://stackoverflow.com/questions/50665429/what-happens-to-the-js-code-inside-em-asm – Navid Jun 03 '18 at 11:28

2 Answers2

3

There is currently not yet a good way to simultaneously run your TFJS model in a users' browser, and also keep your model secret. If model privacy is a design constraint, you will need to either do some sever-side computation, or invent some other solution.

https://github.com/tensorflow/tfjs/issues/239

BlessedKey
  • 1,615
  • 1
  • 10
  • 16
2

An update for those who still wonder about this issue: Tensorflow.js now utilizes WebAssembly under the hood. As noted above, this does not mean your code is inaccessible. Cloistered, obfuscated & unfriendly yes, yet the determined user can still capture, de-compile, & analyze that code. Granted, few users have both the capability & motivation to do so, but it's a big world out there...

Jack
  • 2,229
  • 2
  • 23
  • 37