I am getting the error Invalid argument: NodeDef mentions attr 'Tshape' not in Op<name=Reshape; signature=tensor:T, shape:int32 -> output:T; attr=T:type>; NodeDef: Y_GroundTruth = Reshape[T=DT_FLOAT, Tshape=DT_INT32](LOut_Add, Y_GroundTruth/shape) when attempting to load the file on Android using tensorflow::Status s = session->Create(graph_def);.
People with similar problems have mentioned that upgrading to Tensorflow 0.9.0rc0 fixed their problems. However, I am already using the most current Tensorflow build in my jni-build.
Could this be a problem with the variables declared when generating the protobuf file?
Snippet
def reg_perceptron(t, weights, biases):
t = tf.nn.relu(tf.add(tf.matmul(t, weights['h1']), biases['b1']), name = "layer_1")
t = tf.nn.sigmoid(tf.add(tf.matmul(t, weights['h2']), biases['b2']), name = "layer_2")
t = tf.add(tf.matmul(t, weights['hOut'], name="LOut_MatMul"), biases['bOut'], name="LOut_Add")
return tf.reshape(t, [-1], name="Y_GroundTruth")
g = tf.Graph()
with g.as_default():
...
rg_weights = {
'h1': vs.get_variable("weights0", [n_input, n_hidden_1], initializer=tf.contrib.layers.xavier_initializer()),
'h2': vs.get_variable("weights1", [n_hidden_1, n_hidden_2], initializer=tf.contrib.layers.xavier_initializer()),
'hOut': vs.get_variable("weightsOut", [n_hidden_2, 1], initializer=tf.contrib.layers.xavier_initializer())
}
rg_biases = {
'b1': vs.get_variable("bias0", [n_hidden_1], initializer=init_ops.constant_initializer(bias_start)),
'b2': vs.get_variable("bias1", [n_hidden_2], initializer=init_ops.constant_initializer(bias_start)),
'bOut': vs.get_variable("biasOut", [1], initializer=init_ops.constant_initializer(bias_start))
}
pred = reg_perceptron(_x, rg_weights, rg_biases)
...
...
g_2 = tf.Graph()
with g_2.as_default():
...
rg_weights_2 = {
'h1': vs.get_variable("weights0", [n_input, n_hidden_1], initializer=tf.contrib.layers.xavier_initializer()),
'h2': vs.get_variable("weights1", [n_hidden_1, n_hidden_2], initializer=tf.contrib.layers.xavier_initializer()),
'hOut': vs.get_variable("weightsOut", [n_hidden_2, 1], initializer=tf.contrib.layers.xavier_initializer())
}
rg_biases_2 = {
'b1': vs.get_variable("bias0", [n_hidden_1], initializer=init_ops.constant_initializer(bias_start)),
'b2': vs.get_variable("bias1", [n_hidden_2], initializer=init_ops.constant_initializer(bias_start)),
'bOut': vs.get_variable("biasOut", [1], initializer=init_ops.constant_initializer(bias_start))
}
pred_2 = reg_perceptron(_x_2, rg_weights_2, rg_biases_2)
...
To stop the post from being too cluttered, I have uploaded my code to generate the .PB-file and my model to create the model on Pastebin.
PBFileGeneration
Model
Related
I am using the jitsi meet package for flutter and I have typed the code as per the documentation https://pub.dev/packages/jitsi_meet of the package, but still, there is some error in the app. The error says
The setter 'featureFlag' isn't defined for the type 'JitsiMeetingOptions'.
Try importing the library that defines 'featureFlag', correcting the name to the name of an existing setter, or defining a setter or field named 'featureFlag'.
And this is the joinMeeting function
joinMeeting() async {
print(code);
try {
FeatureFlag featureFlag = FeatureFlag();
featureFlag.welcomePageEnabled = false;
featureFlag.resolution = FeatureFlagVideoResolution.MD_RESOLUTION;
featureFlag.addPeopleEnabled = false;
featureFlag.calendarEnabled = false;
featureFlag.callIntegrationEnabled = false;
featureFlag.inviteEnabled = false;
featureFlag.kickOutEnabled = false;
featureFlag.liveStreamingEnabled = false;
featureFlag.meetingPasswordEnabled = false;
featureFlag.recordingEnabled = false;
featureFlag.serverURLChangeEnabled = false;
featureFlag.tileViewEnabled = false;
featureFlag.videoShareButtonEnabled = false;
if (Platform.isIOS) {
featureFlag.pipEnabled = false;
}
var options = JitsiMeetingOptions()
..room = code // Required, spaces will be trimmed
..userDisplayName = username == null ? 'Unidentified' : username
..audioMuted = false
..videoMuted = false
..featureFlag = featureFlag;
await JitsiMeet.joinMeeting(options);
} catch (err) {
print(err);
}
}
The error is in the line ..featureFlag = featureFlag; which says
The setter 'featureFlag' isn't defined for the type 'JitsiMeetingOptions'.
Try importing the library that defines 'featureFlag', correcting the name to the name of an existing setter, or defining a setter or field named 'featureFlag'.
I have typed everything as per the documentation https://pub.dev/packages/jitsi_meet of the package but still the code does not seems to work. Any help on how to fix this error and make the code working would be of great help.
The featureflag has been changed in new version of jitsi meet plugin 3.0.0, but the changed code hasn't been mentioned in the main page of pub dev I.e https://pub.dev/packages/jitsi_meet. So please check out the example page where new changed syntax has been mentioned i.e https://pub.dev/packages/jitsi_meet/example .
For example your code should look like this, find out which syntax needs to be changed according to new version:-
_joinMeeting() async {
String serverUrl =
serverText.text?.trim()?.isEmpty ?? "" ? null : serverText.text;
// Enable or disable any feature flag here
// If feature flag are not provided, default values will be used
// Full list of feature flags (and defaults) available in the README
Map<FeatureFlagEnum, bool> featureFlags = {
FeatureFlagEnum.WELCOME_PAGE_ENABLED: false,
};
if (!kIsWeb) {
// Here is an example, disabling features for each platform
if (Platform.isAndroid) {
// Disable ConnectionService usage on Android to avoid issues (see README)
featureFlags[FeatureFlagEnum.CALL_INTEGRATION_ENABLED] = false;
} else if (Platform.isIOS) {
// Disable PIP on iOS as it looks weird
featureFlags[FeatureFlagEnum.PIP_ENABLED] = false;
}
}
// Define meetings options here
var options = JitsiMeetingOptions()
..room = roomText.text
..serverURL = serverUrl
..subject = subjectText.text
..userDisplayName = nameText.text
..userEmail = emailText.text
..iosAppBarRGBAColor = iosAppBarRGBAColor.text
..audioOnly = isAudioOnly
..audioMuted = isAudioMuted
..videoMuted = isVideoMuted
..featureFlags.addAll(featureFlags)
..webOptions = {
"roomName": roomText.text,
"width": "100%",
"height": "100%",
"enableWelcomePage": false,
"chromeExtensionBanner": null,
"userInfo": {"displayName": nameText.text}
};
I have a Xamarin Forms app where I've included a font file called Roboto-Regular.ttf in the Assets folder of the Android project. Its Build Action is set to AndroidAsset.
Using the SixLabors.Fonts NuGet package, I'm trying to load this font to use it for watermarking.
However, trying to install the font using the asset stream, an exception is thrown saying:
System.NotSupportedException: Specified method is not supported.
var fonts = new FontCollection();
FontFamily fontFamily;
using (var fontStream = Assets.Open("Roboto-Regular.ttf"))
{
fontFamily = fonts.Install(fontStream); // Fails with "method not supported"
}
return fontFamily;
Any ideas what might be causing this, or if there is a better way to load fonts for use with the SixLabors.ImageSharp package?
Edit: I tried the suggestion below by SushiHangover, but it yields the same result:
There is are two Assets.Open methods and one provides an accessMode (C# Access enum flag set):
using (var fontStream = Assets.Open("Roboto-Regular.ttf", Android.Content.Res.Access.Random))
{
fontFamily = fonts.Install(fontStream);
}
re: https://developer.android.com/reference/android/content/res/AssetManager.html#open(java.lang.String,%20int)
public enum Access
{
[IntDefinition (null, JniField = "android/content/res/AssetManager.ACCESS_BUFFER")]
Buffer = 3,
[IntDefinition (null, JniField = "android/content/res/AssetManager.ACCESS_RANDOM")]
Random = 1,
[IntDefinition (null, JniField = "android/content/res/AssetManager.ACCESS_STREAMING")]
Streaming,
[IntDefinition (null, JniField = "android/content/res/AssetManager.ACCESS_UNKNOWN")]
Unknown = 0
}
Seems the underlying Stream did not have Length or Position properties (which explains the exception), so for now I resorted to converting to a seekable MemoryStream instead:
using (var assetStreamReader = new StreamReader(Assets.Open("Roboto-Regular.ttf"))
{
using (var ms = new MemoryStream())
{
assetStreamReader.BaseStream.CopyTo(ms);
ms.Position = 0;
var fontFamily = new FontCollection().Install(ms);
}
}
Looking at the FontReader implementation, the error now makes even more sense: https://github.com/SixLabors/Fonts/blob/master/src/SixLabors.Fonts/FontReader.cs
However, I'm not sure why Assets doesn't return a seekable stream?
I'm trying to integrate TensorFlow into an Android application. Since I'm new to TensorFlow, I'm proceeding starting with very simple operations.
As a first step I created just the following model:
import tensorflow as tf
with tf.Graph().as_default() as g:
x = tf.placeholder("float", [1, 10], name="input")
a = tf.zeros([10, 5], dtype=tf.float32, name="a")
y = tf.matmul(x, a, name="output")
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
graph_def = g.as_graph_def()
tf.train.write_graph(graph_def, 'models/', 'graph.pb', as_text=False)
This works fine. I'm able to properly get output from my C++ code (and then from Android as well).
I tried then to generate a by using tf.random_normal. It seems this is not feasible by just replacing tf.zeros with tf.random_normal. That's because tf.zeros returs a costant, while tf.random_normal not. In particular it seems I must handle it as a variable.
Idea I followed is the same proposed in other examples I've found on GitHub... so, evaluating a before writing the graph, as reported in code below:
import tensorflow as tf
a = tf.Variable(tf.random_normal([10, 5], dtype=tf.float32), name="a")
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
a_eval = a.eval(sess)
# print here properly produces matrix in output
print a_eval
sess.close()
with tf.Graph().as_default() as g:
x = tf.placeholder(tf.float32, [1, 10], name="input")
a_2 = tf.constant(a_eval, name="a_2")
y = tf.matmul(x, a_2, name="output")
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
graph_def = g.as_graph_def()
tf.train.write_graph(graph_def, 'models/', 'graph.pb', as_text=False)
Unfortunately it seems it doesn't work due to an error occurring in reading binary file:
Out of range: Read less bytes than requested
This is C++ code that I'm currently using for loading graph from file:
tensorflow::GraphDef graph_def;
Status load_graph_status = ReadBinaryProto(Env::Default(), filepath, &graph_def);
if (!load_graph_status.ok()) {
LOG(ERROR) << "could not create tensorflow graph: " << load_graph_status;
return NULL;
}
Hope someone could help me with this problem.
I've created webservice on desktop (jdk, working good) and i'm trying to move it to android (make it running on android device). But i'm having some issues and after debugging for few days i've found different behaviour of the next code:
Schema schema = TXW.create(Schema.class,ResultFactory.createSerializer(result));
Passed result object is almost empty before invocation and has only systemId property. On JDK created schema has not null nsUri property, but on Android it's just empty!
JDK:
Android:
What's the reason and how can i fix it?
It makes schema invalid and it throws exception in cxf later:
javax.xml.ws.WebServiceException: java.lang.RuntimeException: Invalid schema document passed to AbstractDataBinding.addSchemaDocument, not in W3C schema namespace: schema
Update1:
I'v found TXW code pkg.getAnnotation(XmlNamespace.class) return null in android but instance value in jdk:
if(nsUri.equals("##default")) {
Package pkg = c.getPackage();
if(pkg!=null) {
XmlNamespace xn = pkg.getAnnotation(XmlNamespace.class); // xn = null in android
if(xn!=null)
nsUri = xn.value();
}
}
if(nsUri.equals("##default"))
nsUri = "";
return new QName(nsUri,localName);
The reason was in TXW.java:
Package pkg = c.getPackage();
XmlNamespace xn = pkg.getAnnotation(XmlNamespace.class);
if(xn!=null) // always null in android as it does not support package annotations
nsUri = xn.value();
So i had to hack it - create public static variable and set it before:
public static java.lang.String XmlNamespaceAnnotationValue = null;
...
Package pkg = c.getPackage();
if(pkg!=null) {
if (XmlNamespaceAnnotationValue != null) {
nsUri = XmlNamespaceAnnotationValue;
} else {
XmlNamespace xn = pkg.getAnnotation(XmlNamespace.class);
if(xn!=null)
nsUri = xn.value();
}
}
Before usage:
TXW.XmlNamespaceAnnotationValue = "http://www.w3.org/2001/XMLSchema";
I am new to Unity so a well stepped out answer would be nice. I am trying to make a dice roller on an Android platform. I was following this very well put together tutorial http://games.ucla.edu/resource/unity-1-beginner-tutorial-dice-making-pt-1/ (There is a second part too)
The problem is that it was made for a Web Player. If I try to build it for Android I get two particular errors.
I have two simple scripts with one error associated with each one.
SideTrigger.js - Error: BCE0019: 'currentValue' is not a member of 'UnityEngine.Component'.
public var faceValue = 0;
function OnTriggerEnter( other : Collider ) {
var dieGameObject = GameObject.Find("SixSidedDie");
var dieValueComponent = dieGameObject.GetComponent("DieValue");
dieValueComponent.currentValue = faceValue; //ERROR HERE
Debug.Log("Die1: " + faceValue);
}
DieValue.js - Error: BCE0019: 'text' is not a member of 'UnityEngine.Component'.
public var currentValue = 0;
function Update () {
var dieTextGameObject = GameObject.Find("DieText");
var textMeshComponent = dieTextGameObject.GetComponent("TextMesh");
textMeshComponent.text = currentValue.ToString(); //ERROR HERE
}
I'm assume it's purely a syntactical issue, but I can't seem to find a solution.
GetComponent using string is not recommended due to performance reasons, it is documented here.
It is better to use this:
var dieValueComponent : DieValue = dieGameObject.GetComponent(DieValue)
Or this:
var dieValueComponent : DieValue = dieGameObject.GetComponent.<DieValue>()
See if that works.