Skip to content

Commit 605775f

Browse files
committed
API change for TensorflowComponent
-TensorInputs renamed to JsonInputs which is more accurate -added sync custom function allowing much more open api. Specify the desired function name and arguments in string format and return a string. Json encoding recommended. -using python case for tf component -breaking api
1 parent 88fea0e commit 605775f

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Content/Scripts/TensorFlowComponent.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def end_play(self):
3939
self.ValidGameWorld = False
4040
self.tfapi.stop()
4141

42-
#tensor input
43-
def tensorinput(self, args):
42+
#json input
43+
def json_input(self, args):
4444
if(self.uobject.VerbosePythonLog):
4545
ue.log(self.uobject.TensorFlowModule + ' input passed: ' + args)
4646

@@ -51,14 +51,14 @@ def tensorinput(self, args):
5151
self.uobject.OnResultsFunction(json.dumps(resultJson))
5252

5353
#training callback function
54-
def trainingComplete(self, summary):
54+
def training_complete(self, summary):
5555
if(self.uobject.VerbosePythonLog):
5656
ue.log(self.uobject.TensorFlowModule + ' trained in ' + str(round(summary['elapsed'],2)) + ' seconds.')
5757

5858
self.uobject.OnTrainingCompleteFunction(json.dumps(summary))
5959

6060
#single threaded call
61-
def trainBlocking(self):
61+
def train_blocking(self):
6262
if(self.uobject.VerbosePythonLog):
6363
ue.log(self.uobject.TensorFlowModule + ' training started on bt thread.')
6464

@@ -80,7 +80,7 @@ def trainBlocking(self):
8080

8181
#run callbacks only if we're still in a valid game world
8282
if(self.ValidGameWorld):
83-
ue.run_on_gt(self.trainingComplete, summary)
83+
ue.run_on_gt(self.training_complete, summary)
8484

8585
#multi-threaded call
8686
def train(self, args=None):
@@ -89,9 +89,17 @@ def train(self, args=None):
8989

9090
if(self.uobject.ShouldUseMultithreading):
9191
try:
92-
ut.run_on_bt(self.trainBlocking)
92+
ut.run_on_bt(self.train_blocking)
9393
except:
9494
e = sys.exc_info()[0]
9595
ue.log('TensorFlowComponent error: ' + str(e))
9696
else:
97-
self.trainBlocking()
97+
self.train_blocking()
98+
99+
#allow call custom functions on the tfapi object. Note all of these are synchronous
100+
def custom_function(self, args=None):
101+
#split our custom function call by first ','
102+
stringList = args.split(',', 1)
103+
104+
#call our custom function with our passed variables and return result
105+
return getattr(self.tfapi, stringList[0])(stringList[1])

Content/TensorflowComponent.uasset

22.7 KB
Binary file not shown.

TensorFlow.uplugin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"FileVersion": 3,
33
"Version": 1,
4-
"VersionName": "0.1.5",
4+
"VersionName": "0.2.0",
55
"FriendlyName": "TensorFlow",
66
"Description": "Unofficial TensorFlow plugin for UE4. Enables state of the art machine learning via python and blueprints.",
77
"Category": "Computing",

0 commit comments

Comments
 (0)