Programmatically set transformer parameters in FME2015 - c#

I am trying to upgrade my application from FME2009 to FME2015. The problem I'm running into is it seems like the parameters I set are not being used in the actual transformer. Instead, the default values from the transformer definition are being used. Specifically, the source and destination coordinate system names are not being applied.
Setting the parameters in this way worked perfectly when my application was linked against FME2009.
Code excerpt:
StringCollection directives = new StringCollection();
directives.Add(Safe.FMEObjects.Constants.TransformerManager.CreateTransformerDirectives.SerializationString);
parameters = String.Format("\"SOURCE_COORDSYS,{0},XFORMER_NAME,SpineClipTransformer,DEST_COORDSYS,{1}\"", sourceCSys, destCSys);
directives.Add(String.Format("NAME,SpineClipTransformer,VERSION,0,PARAMETER_VALUES,{0},INPUT_FEATURE_TYPES,,INPUT_FILTERS,,INPUT_ATTRS,,OUTPUT_FEATURE_TYPES,,OUTPUT_FUNCTIONS,", parameters));
transformer = fme.TransformerManager().CreateTransformer(directives);
When I execute this code I can see from the logs that the default values are being used.
Log excerpt:
Coordinate system named TOM_PRICE_MINE_MGA does not exist.
BADNEWS: No definition was found for coordinate system `TOM_PRICE_MINE_MGA(TOM_PRICE_MINE_MGA)' (crdsysmn.cpp:1074)
Coordinate system named TOM_PRICE_MINE_MGA does not exist.
BADNEWS: Unknown coordinate system 'TOM_PRICE_MINE_MGA' specified - aborting (crdsysmn.cpp:1628)
Unknown coordinate system 'TOM_PRICE_MINE_MGA' specified - aborting
BADNEWS: Reprojector: Could not create reprojection engine (fmereprojector.cpp:404)
Reprojector: Could not create reprojection engine
Transformer excerpt:
<GLOBAL_PARAMETERS>
<GLOBAL_PARAMETER
GUI_LINE="GUI COORDSYS DEST_COORDSYS Destination Coordinate System:"
DEFAULT_VALUE="EPSG:28350"
IS_STAND_ALONE="false"
/>
<GLOBAL_PARAMETER
GUI_LINE="GUI COORDSYS SOURCE_COORDSYS Source Coordinate System:"
DEFAULT_VALUE="TOM_PRICE_MINE_MGA"
IS_STAND_ALONE="false"
/>
</GLOBAL_PARAMETERS>
...
DEFAULT_MACRO DEST_COORDSYS EPSG:28350
DEFAULT_MACRO SOURCE_COORDSYS TOM_PRICE_MINE_MGA
Edit 1
I found the IFMEOTransformer.Serialize method and ran it after I instantiated the transformer.
My directive: NAME,SpineClipTransformer,VERSION,0,PARAMETER_VALUES,"SOURCE_COORDSYS,LL-GDA94,XFORMER_NAME,SpineClipTransformer,DEST_COORDSYS,MGA94-50",INPUT_FEATURE_TYPES,,INPUT_FILTERS,,INPUT_ATTRS,,OUTPUT_FEATURE_TYPES,,OUTPUT_FUNCTIONS,
IFMEOTransformer.Serialize() output: NAME,SpineClipTransformer,VERSION,1,PARAMETER_VALUES,"__COMPOUND_PARAMETERS,,XFORMER_NAME,SpineClipTransformer,TRANSFORMER_GROUP,",INPUT_FEATURE_TYPES,,INPUT_FILTERS,,INPUT_ATTRS,,OUTPUT_FEATURE_TYPES,,OUTPUT_FUNCTIONS,
Attempting to follow this format (without knowing anything about it), I changed my directive to: NAME,SpineClipTransformer,VERSION,1,PARAMETER_VALUES,"__COMPOUND_PARAMETERS,SOURCE_COORDSYS,LL-GDA94,XFORMER_NAME,SpineClipTransformer,DEST_COORDSYS,MGA94-50,TRANSFORMER_GROUP,",INPUT_FEATURE_TYPES,,INPUT_FILTERS,,INPUT_ATTRS,,OUTPUT_FEATURE_TYPES,,OUTPUT_FUNCTIONS,
New IFMEOTransformer.Serialize() output: NAME,SpineClipTransformer,VERSION,1,PARAMETER_VALUES,"__COMPOUND_PARAMETERS,SOURCE_COORDSYS,XFORMER_NAME,SpineClipTransformer,TRANSFORMER_GROUP,",INPUT_FEATURE_TYPES,,INPUT_FILTERS,,INPUT_ATTRS,,OUTPUT_FEATURE_TYPES,,OUTPUT_FUNCTIONS,

Related

How to create and setup ONVIF PresetTour using onvif ver20 ptz.wsdl

I would like to know how to create and setup a PresetTour using the ONVIF standard.
Using the the ONVIF ptz wsdl that has been added to my c# project's Connected Services, I can see that I can create a PresetTour for my PTZClient.
_ptzClient.CreatePresetTour(_profile.token);
After using this command, I can get the infos of this newly created preset tour using:
PresetTour[] tours = _ptzClient.GetPresetTours(_profile.token);
I would like to know how to create a new TourSpot or use an already existing Preset as a TourSpot to make my camera go to this spot when launching/starting the preset tour/patrol on my camera.
How do I set the position of a newly created tour spot?
How am I supposed to configure an entire PresetTour?
If there is no solution to my problem, I think I'll keep a list of preset on the side of my application and do everything manually.
You need to invoke ModifyPresetTour. It requires a tt:PresetTour struct, which has, among other fields, a TourSpot element of type tt:PTZPresetTourSpot. Beware that TourSpot is defined in the XML schema as minOccurs="0" maxOccurs="unbounded", thus you can specify any number of tour spots.
The PTZPresetTourSpot struct has a PresetDetail filed of type tt: PTZPresetTourPresetDetail.
Finally PTZPresetTourPresetDetail has a PresetToken field, where you can specify the preset.
I agree it is not very programmer-friendly.

Full type name followed by index, what does it mean?

I am trying to understand the logging output of dotnet run for an ASP.NET Core project. There are many places showing a full type name followed by what appears to be the indexer syntax.
This page explains how array types are represented, but in that case there is no index.
Console.WriteLine(new string[100]); shows:System.String[]
This is an actual dotnet run output:info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58]
How to interpret the previous text? What is 58?
Is it a general C# string representation? What code construct would output something like that?
In the example provided, there are three components:
info, which is the log level.
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager, which is the log category.
58, which is the log event ID.
ASP.NET Core uses ILogger and ILogger<T> for logging, using calls such as:
logger.LogInformation(...);
The example log message you've shown is from a console provider, which has its own rules about how to format the message. By default, this starts with a header line of level: category[eventID], as I've shown.
As a crude example, you might imagine the following code being used to generate the final message:
var logLevel = "info";
var logCategory = "Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager";
var logEventId = 58;
Console.Writeline($"{logLevel}: {logCategory}[{logEventId}]");

TensorflowSharp - TFException: Attempting to use uninitialized value

I'm attempting to import a model created in Keras/Tensorflow and use it for inference in a Unity project.
I have successfully imported the model and validated by printing names of input and output nodes in the graph. Though, when I try to get the output value from the runner, I get this exception.
TFException: Attempting to use uninitialized value action_W
[[Node: action_W/read = IdentityT=DT_FLOAT, _class=["loc:#action_W"], _device="/job:localhost/replica:0/task:0/cpu:0"]]
TensorFlow.TFStatus.CheckMaybeRaise (TensorFlow.TFStatus incomingStatus, System.Boolean last) (at <6ed6db22f8874deba74ffe3e566039be>:0)
TensorFlow.TFSession.Run (TensorFlow.TFOutput[] inputs, TensorFlow.TFTensor[] inputValues, TensorFlow.TFOutput[] outputs, TensorFlow.TFOperation[] targetOpers, TensorFlow.TFBuffer runMetadata, TensorFlow.TFBuffer runOptions, TensorFlow.TFStatus status) (at <6ed6db22f8874deba74ffe3e566039be>:0)
TensorFlow.TFSession+Runner.Run (TensorFlow.TFStatus status) (at <6ed6db22f8874deba74ffe3e566039be>:0)
RecordArbitraryData.ModelPredict (System.Single[,] input) (at Assets/Scripts/Spells/RecordArbitraryData.cs:230)
RecordArbitraryData.FixedUpdate () (at Assets/Scripts/Spells/RecordArbitraryData.cs:95)
Here are the two functions I use. InstantiateModel is called OnStart() in my unity script. And ModelPredict is called when the user passes an input to the script.
void InstantiateModel(){
string model_name = "simple_as_binary";
//Instantiate Graph
graphModel = Resources.Load (model_name) as TextAsset;
graph = new TFGraph ();
graph.Import (graphModel.bytes);
session = new TFSession (graph);
}
void ModelPredict(float[,] input){
using (graph) {
using (session) {
//Assign input tensors
var runner = session.GetRunner ();
runner.AddInput (graph [input_node_name] [0], input);
//Calculate and access output of graph
runner.Fetch (graph[output_node_name][0]);
Debug.Log ("Output node name: " + graph [output_node_name].Name);
float[,] recurrent_tensor = runner.Run () [0].GetValue () as float[,];
//var results = runner.Run();
//Debug.Log("Prediciton: " + results);
}
}
}
Any help appreciated - TensorflowSharp is very new to me.
I was able to figure out most of my problems. I'm currently at a point where my model is predicting in unity, but only predicting the first of four classes. My guess is it has something to do with the weights not getting initialized correctly from the checkpoint files? Edit: My values weren't being normalized before being passed to neural network.
Preface: Mozilla Firefox works best for displaying tensorboard; it took me a long time to realize that google chrome was causing my graph to be invisible (tensorboard is how I was able to figure out the nodes that needed to be used for input and output).
First Issue: I was renaming a .pb file into a .bytes file. This is incorrect because the model’s weights come from the checkpoint file, and are given to the nodes held in the .pb file. This was causing the uninitialized variables. These variables were used for training, which were removed after using the freeze_graph function.
Second Issue: I was using the file created called ‘checkpoint’, which was throwing an error. I then changed the name of the checkpoint to ‘test’ and used this in the freeze_graph function. When calling the checkpoints file, I was required to use ‘test.ckpt’. I assume this function knows to grab the three files automatically based on the .ckpt? ‘Test’ without ‘.ckpt’ did not work.
Third Issue: when using the freeze_graph function, I needed to export the .pb file in keras/tf with text=False. I tested True and False; True threw an error about “bad wiring”.
Fourth Issue: Tensorboard was very difficult to use without any organization. Using tf.name_scope helped a lot with not only visualization, but making sure I was using/referencing the correct nodes in TensorFlowSharp. In keras I found it helpful to separate the final Dense layer and Activation into their own scopes so I could find the correct output node. The rest of my network was put into a ‘body’ scope, and the sole input layer in ‘input’ scope. The name_scope function prepends ‘scopename/’ to the node name. I don't think it’s necessary, but it helped me.
Fifth Issue: The version of tensorflowsharp released as a unity package is not up to date. This caused an issue with a keras placeholder for ‘keras_training_phase’. In keras, you pass this along with an input like [0] + input. I tried to do the same by creating a new TFTensor(bool), but I was getting an error ‘inaccessible due to its protection level. This was an error with the implicit conversion between bool and TFTensor in my unity TensorFlowSharp version. To fix this I had to use a function found in this stackoverflow solution where the .bytes file is read in, the placeholder for keras_training_phase is found, and is swapped out for a bool constant set to false. This worked for me because my model was pretrained in python, so it may not be a great fix for someone that’s trying to train and test the model. A condition for removing this node with the freeze_graph function would really be useful.
Hope someone finds this useful!

Transforming XML with XSL to HTML Saxon library in .NET

I am programming in C#. I was previously using the following command line to convert an xml with a xsl and output it as a html.
java -jar "C:\Data\saxon-he-9.4.0.7.jar" View.xml Stylesheet.xsl -o:output.html
However, I am now trying to use the Saxon .Net API to do the same process using the following code:
var xslt = new FileInfo(#"C:\\Data\\Stylesheet.xsl");
var input = new FileInfo(#"C:\\Data\\View.xml");
var output = new FileInfo(#"C:\\Data\\test.html");
// Compile stylesheet
var processor = new Processor();
var compiler = processor.NewXsltCompiler();
var executable = compiler.Compile(new Uri(xslt.FullName));
// Do transformation to a destination
var destination = new DomDestination();
using (var inputStream = input.OpenRead())
{
var transformer = executable.Load();
transformer.SetInputStream(inputStream, new Uri(input.DirectoryName));
transformer.Run(destination);
}
// Save result to a file (or whatever else you wanna do)
destination.XmlDocument.Save(output.FullName);
However I recieve the error:
"An unhandled exception of type 'Saxon.Api.DynamicError' occurred in saxon9he-api.dll"
When running the line "transformer.Run(destination);"
The following screenshots are from the Visual Studio's Locals Debugging:
$exception {"XSLT 1.0 compatibility mode is not available in this configuration"} Saxon.Api.DynamicError
transformer {Saxon.Api.XsltTransformer} Saxon.Api.XsltTransformer
The first thing you need to do is to get more specific information about the nature of the error. Catching the exception and printing the exception message would be a good start. But Saxon will have written diagnostics to the standard error output, which probably ends up in some log file somewhere, depending on how your application is configured and run. If you can't track it down, try redirecting it as described here: How to capture a Processes STDOUT and STDERR line by line as they occur, during process operation. (C#)
Once you've established the actual error, edit the question and we can start investigating what's wrong if it's not obvious.
A common cause of problems when writing to a DomDestination is that your result tree isn't well-formed, e.g, it has text nodes or multiple elements at the top level. It's not clear why you are writing to a DomDestination - if you just want to produce serialized XML, then write to a Serializer.
LATER
Now you've found the error message ("XSLT 1.0 compatibility mode is not available in this configuration") it should be fairly clear. When a stylesheet specifies version="1.0" and is run with an XSLT 2.0 or 3.0 processor, it runs in a compatibility mode where certain things behave differently (for example xsl:value-of ignores all but the first selected item). This compatibility mode, from Saxon 9.8 onwards, is not available in Saxon-HE. You need to do one of three things: upgrade to Saxon-PE or -EE; revert to an earlier Saxon-HE version; or convert your stylesheet to XSLT 2.0 (which basically means (i) change the value of the version attribute (ii) test that it still works.)

BizTalk Dynamic Disassembler Problems - The body part is NULL

I started with the solution here http://social.technet.microsoft.com/wiki/contents/articles/20547.biztalk-server-dynamic-schema-resolver-real-scenario.aspx
which matches my scenario perfectly except for the send port, but that isn't necessary. I need the receive port to choose the file and apply a schema to disassemble. From their the orchestration does the mapping, some of it custom, etc.
I've done everything in the tutorial but I keep getting the following error.
"There was a failure executing the receive pipeline... The body part is NULL"
The things I don't get from the tutorial but don't believe they should be an issue are:
I created a new solution and project to make the custompipeline component (reference figure 19) and thus the dll file. Meaning it is on it's own namespace. However, it looks like from the tutorial they created the project within the main biztalk solution (ie the one with the pipeline and the orchestration) and thus the namespace has "TechNetWiki.SchemaResolver." in it. Should I make the custompipeline component have the namespace of my main solution? I'm assuming this shouldn't matter because I should be able to use this component in other solutions as it is meant to be generic to the business rules that are associated with the biztalk application.
The other piece I don't have is Figure 15 under the "THEN Action" they have it equal the destination schema they would like to disassemble to but then they put #Src1 at the end of "http://TechNetWiki.SchemaResolver.Schemas.SRC1_FF#Src1". What is the #Src1 for?
In the sample you've linked to, the probe method of the pipeline component is pushing the first 4 characters from the filename into a typed message that is then passed into the rules engine. Its those 4 characters that match the "SRC1" in the example.
string srcFileName = pInMsg.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties This link is external to TechNet Wiki. It will open in a new window. ").ToString();
srcFileName = Path.GetFileName(srcFileName);
//Substring the first four digits to take source code to use to call BRE API
string customerCode = srcFileName.Substring(0, 4);
//create an instance of the XML object
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(string.Format(#"<ns0:Root xmlns:ns0='http://TechNetWiki.SchemaResolver.Schemas.SchemaResolverBRE This link is external to TechNet Wiki. It will open in a new window. '>
<SrcCode>{0}</SrcCode>
<MessageType></MessageType>
</ns0:Root>", customerCode));
//retreive source code in case in our cache dictionary
if (cachedSources.ContainsKey(customerCode))
{
messageType = cachedSources[customerCode];
}
else
{
TypedXmlDocument typedXmlDocument = new TypedXmlDocument("TechNetWiki.SchemaResolver.Schemas.SchemaResolverBRE", xmlDoc);
Microsoft.RuleEngine.Policy policy = new Microsoft.RuleEngine.Policy("SchemaResolverPolicy");
policy.Execute(typedXmlDocument);
So the matching rule is based on the 1st 4 characters of the filename. If one isn't matched, the probe returns a false - i.e. unrecognised.
The final part is that the message type is pushed into the returned message - this is made up of the namespace and the root schema node with a # separator - so your #src1 is the root node.
You need to implement IProbeMessage near to class
I forgot to add IProbeMessage in the code of article. It is updated now.
but it is there in sample source code
Src1 is the the root node name of schema. I mentioned that in article that message type is TargetNamespace#Root
I recommend to download the sample code
I hope this will help you

Categories

Resources