Unreal.js icon indicating copy to clipboard operation
Unreal.js copied to clipboard

Support for External Frameworks like Tensorflow.js

Open krumiaa opened this issue 5 years ago • 17 comments

Ran into errors getting this to work with Tensorflow.js, specifically SyntaxError: Unexpected token * when using import * as tf from '@tensorflow/tfjs'; to load the tensor flow. Is Unreal JS fundamentally incompatible with external packages like Tensorflow or am I missing something?

krumiaa avatar Sep 21 '18 15:09 krumiaa

Use an api exposed to Unreal such as https://github.com/getnamo/tensorflow-ue4.

crocuis avatar Oct 02 '18 02:10 crocuis

@krumiaa Hi. Do you find any solution? I writed some code that you want to use 'TFJS'. Check my repo(https://github.com/keicoon/Deep-Learning/tree/master/DQN). It has dependencies about unreal.js and @tensorflow/tfjs.

keicoon avatar Oct 11 '18 07:10 keicoon

Did you get this DQN repo to work with Unreal.js? When I tried to load tfjs as a dependency, it threw a bunch of errors....

krumiaa avatar Oct 12 '18 14:10 krumiaa

You don't need to install npm/@tfjs directly, just inject js code const tf = require('./lib/fancyLoadNPM')('@tensorflow/tfjs', global);. It help that loads cycling dependancies by downloading tfjs and making to bundle.

keicoon avatar Oct 16 '18 07:10 keicoon

Still not sure how you got this working keicoon , was it with a node install of tensorflow.js or via npm? Trying to run example-dqn-tfjs.js from your DQN repository, kept pulling errors like module ReferenceError: module is not defined or ReferenceError:process is not defined. Is it possible you could share the unreal project file or do a step by step run through of the install. I tried it on Unreal 4.19

krumiaa avatar Oct 19 '18 22:10 krumiaa

@krumiaa Hi! Thanks for your review. It has some problem due to npm's latest update that not allowed '@' keyword by module name. So, I updated github code and uploaded full content be tested in UE4.19 project to gitlab.

keicoon avatar Oct 22 '18 13:10 keicoon

Tried the project from getlab as well as the new github code but getting error: Cannot read property 'train' of undefined. See image. Thinking this maybe some version specific glitch. Am using npm 6.4.1 and Unreal.js ver 0.3.1 with Unreal 4.19. I didnt see that tensorflow was installed in the scripts directory of your project so i tried npm install @tensorflow/tfjs to the /scripts but still not working. Any other suggestions for how to replicate this? Maybe I'm missing something obvious? dqn_error

krumiaa avatar Oct 25 '18 15:10 krumiaa

Hi! I am using tensorflow.js bundle file that made by browserify. It will be generated by Scripts/bundle_tensorflow_tfjs.js. So, you first check bundle_tensorflow_tfjs.js file be existed. If not existed, Run below command repeatedly until tf is not empty.

tf = require('dqn\lib\fancyLoadNPM')('@tensorflow/tfjs', global)
console.log(tf)

If you don't want to follow, you can also make bundle file using browserify by independent command. Thank YOU :)

keicoon avatar Oct 28 '18 02:10 keicoon

Thank you so much for helping explain this. After hours and hours, I still have not managed to get it working. Do I need browserfy installed in order to run the project as you have made it? the only way i get console.log(tf) to rerturn anything is with const tf = require('/dqn/lib/fancyLoadNPM')('bundle_tensorflow_tfjs.js', global); but this creates multiple versions of bundle_tensorflow_tfjs.js in the scripts directory and basic tensorflow functions like const model = tf.sequential(); still wont work. Any change u could post some stimple step by step setup instructions for loading all the dependencies on the github page?

krumiaa avatar Oct 28 '18 19:10 krumiaa

@krumiaa looking at fancyLoadNPM, it appears to require you to have node installed separately, do you have it installed?

getnamo avatar Oct 28 '18 19:10 getnamo

Yes, this solution need to install nodejs that he said. Because, I use command(JavascriptProcess.Create('node', ...)) that has dependency about nodejs. Let's install nodejs 8.x.x. :)

keicoon avatar Oct 29 '18 13:10 keicoon

Curious if anyone has managed to replicate this and what if any changes were necessary? Iv been banging my head against it for a week. Yes, have node 8.12 installed. Wondering if there are some build path issues with the fancyLoadNPM code, parts that have to be modified depending on where node was installed or where game assets are located. Or perhaps dependent on using a particular version of node. Cant think of any other reasons the project file wouldn’t work out of the box. Or perhaps Browserify must be installed at a particular location, noticed its referenced in fancyLoadNPM. Allot of moving parts. Not even sure why FancyLoadNPM is required, what purpose it is serving here different from NPM. Would be helpful if some of this was laid out in the documentation, though I suppose that would take away all the fun ;-)

krumiaa avatar Oct 29 '18 16:10 krumiaa

Simply, I would explain why need to use browerify and node that not v8. First unreal.js not support npm module officially so we can't use @tensorflow.js directly. And v8 is different to node about loading module system has circularly issue. So, I use trick will resolve circular dependency module issue using browserify. Lastly, I will upload bundle script that be browserified about tensorflow.js for you :)

keicoon avatar Oct 31 '18 06:10 keicoon

Very much appreciate the work you have done on this keicoon and believes it really opens up some cool possibilities for doing machine learning in Unreal. Really confused on how to replicate though so anything you can do to make the process simpler, such as the bundle script you mentioned, would be awesome.

krumiaa avatar Nov 01 '18 00:11 krumiaa

@krumiaa Hi! Download this file bundle_tensorflow_tfjs.js. and put it in Content\Scripts :)

keicoon avatar Nov 01 '18 14:11 keicoon

Hi keicoon, thanks for uploading this. I noticed a similar bundle file in your unreal project scripts directory, wasn't sure what the the proper way to deploy it is. Does one still need the fancyLoadNPM to access this bundle file or can I just call it like const tf = require('bundle_tensorflow_tfjs', global); Thanks for clarifying

krumiaa avatar Nov 06 '18 21:11 krumiaa

I got this to work as well very cool! Didn't even think about possibilities with tensorflow etc cool stuff! I hope to share some cool stuff soon.

Master244 avatar May 19 '20 12:05 Master244