How do I convert Niftynet models into .pb format - tensorflow.js

I would like to use models in Niftynet zoo in tensorflowjs.
When I download models from Niftynet zoo they are in checkpoint format (ckpt). However, tensorflowjs expects the models to be in pb format. Also, checkpoint format does not contain graph information so we need to save the model using simple_save or similar API [1].
So what I intend to do is to do:
Download a model from Niftynet zoo
Restore it. (I need help in this step)
Save the complete model using simple_save api. This will result in .pb model. (I need help in this step)
Use tensorflowjs-converter [2] to convert it into pb format which can be consumed by tensorflowjs.
So can someone from niftynet community help me with steps 2 and 3: how to load a model using the checkpoint files and configuration file and save it completely using the simple_save api.
https://www.tensorflow.org/guide/saved_model
https://js.tensorflow.org/tutorials/import-saved-model.html

Related

Converting a sharded Tesorflow Model

I want to use a tensorflow.js model in a react native app locally as asset. the problem is that the web optimized model uses sharded weights in multiple files. But the react native bundleResourceIO handler expects only one file. I have tried to convert the model with the tensorflowjs_converter. Unfortunately without success because I do not know exactly what the command expects for parameters. I have for example tried the following:
tensorflowjs_converter --weight_shard_size_bytes 60000000 --input_format tfjs_layers_model --output_format tfjs_layers_model model.json unsharded_model
anyone converted a model succesfully?
the answer is found here:
https://stackoverflow.com/a/64213104/1886202
if you have multiple sharded weight files just concat them in your console
cat file1.bin file2.bin file3.bin > newfile.bin

How to parse JSON-LD feed using dotNetRDF in C#

I'm trying to consume a json-ld formatted endpoint in a dotnet app.
I've not come across this format before but most of the examples are for JavaScript.
I've tried a couple of libraries and simply failing because there is so little reference.
I've loaded the contents of the endpoint into memory, now I want to see how best to traverse the nodes, but I can't take the contents and do anything with them.
The simplest example OUGHT to look something like:
JsonLdParser parser = new JsonLdParser();
parser.Load(contentsfromuri)
However, the above requires you to have an IRdfReader declared, which cannot be instantiated as its an abstract class.
You'll find the dotNetRDF documentation all at https://github.com/dotnetrdf/dotnetrdf/wiki. There are some examples of parsing RDF data from various sources at https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Reading-RDF. In RDF there are syntaxes that only ever serialize a single graph and syntaxes that can serialize multiple graphs - JSON-LD is one of the latter, so you need to also read the section on Store Readers.
The following examples all show loading the data into an in-memory store.
If your content source is "well-behaved" (sends back the right sort of Content-Type headers, or has the expected file name suffix if it is a local file), then loading the data can be as simple as creating a new in-memory graph and calling its Load method:
var store = new TripleStore();
# This is a convenience wrapper that simply invokes UriLoader.Load()
store.LoadFromUri(contentSourceUri)
NOTE: This uses an extension method (as described at https://github.com/dotnetrdf/dotnetrdf/wiki/UserGuide-Extension-Methods) which is just a convenience wrapper around:
# Create the store
var store = new TripleStore();
# UriLoader will make an HTTP request and parse the response,
# selecting the parser to be used based on the Content-Type header returned.
UriLoader.Load(store, contentSourceUri);
If you are parsing from a string that you have already retrieved, or if you need to be explicit about the parser instance to use (this may be the case if you want to pass some options to the parser when you create it for example), then you need a slightly more verbose approach:
var store = new TripleStore();
# Create the parser (we can pass in options here if needed)
var parser = new JsonLdParser();
# Wrap the string content in a StringReader and pass the target graph and the reader
parser.Load(store, new StringReader(contentsFromUri));
One final thing to note as you specifically refer to JSON-LD. The parser is a conformant JSON-LD 1.0 parser but it's JSON-LD 1.1 support is based on an earlier draft of the spec. I'm currently working on updating the implementation and hope to have a new release that supports the JSON-LD 1.1 Proposed Recommendation in a few weeks.

CakePHP - How to perform unit conversions?

How to perform a unit convertion in a nice way with CakePHP?
I have all mesurment values saved in "mm" in the database, if the user has another perfered mesurmentsystem then "metric" i need to convert and display the mesurments in that system.
Make a lib class in /Lib where you put the basic conversion stuff.
Then you either use it as Lib directly anywhere in your app (model etc) or you can extend it as a helper for your view level.
Check out how the core does it with CakeNumber and NumberHelper, CakeTime and TimeHelper and String and TextHelper.
Analogously should you code your measurement conversion.

media files converter plugin/component in CakePHP

I am trying to develop a plugin/component that can change the media file format from one to another. Specifically, I need it to convert the "tiff" file to array/single copy of "jpg" image file.
Kindly guide, how I can implement it or is there any kind of tutorial link from where either I can download it or take some help to develop it. Thanks in advance.
We did this in our CMS (built on CakePHP 1.2; sorry if there are any significant discrepancies I'm not aware of) using a behaviour. That makes the controller logic very easy (in fact we use a baked controller without any modification at all).
Unfortunately TIFF isn't a supported file format in GD (the default image manipulation library in PHP). You'll need to use ImageMagick or an equivalent tool to do the actual conversion itself, but the logic for implementing it in your CakePHP project won't be any different to what I describe here.
The behaviour (in our case) was used to generate images as thumbnails as well as page resolution and to convert the uploaded file format into JPEG.
In its beforeSave() method it checked that data was specified (and that there was no error), and then pulled the tmp_name value from the posted data (and removed the posted data object).
In its afterSave() method, it actually performed the image conversion task itself (putting the generated images in the expected location on disk), then updated any foreign keys on extended models with the uploaded image's ID. We do this in the afterSave() operation so we have a database ID to use to name the files on disk.
In its afterDelete() method we unlink the files on disk.
Using the behaviour in the model is as simple as telling the model (where ContentImage is the name of the behaviour):
var $actsAs = array('ContentImage');
Although we also use the model to define the output directory since we had a few models that implemented the behaviour, and it felt like the right thing to do, e.g. in the model:
function getThumbnailDir() {
return WWW_ROOT.'img'.DS.'upload'.DS.'thumb';
}
and in the behaviour itself the output path becomes:
$Model->getThumbnailDir().DS.$Model->id.'.jpg'

dynamic map managment in google earth

My goal is to display various shapes(polygons, points, linestring) on google maps by using data entered into a Postgis database dynamically(i mean by that we can see modifications in the map in real time).
I was looking for a way to do this that used the spatial structure already provided in postgis(already designating if shape is a linestring or polygon, etc) instead of parsing out the coordinates and then re-entering spatial structure in google maps. I saw that google maps api is now compatible with kml data formats. And then I read that i have to convert postgis data to kml format.
I've done some reading in the forums about the actual process of converting postgis data to kml via FWTools, but didn't see anything that would help me. I'm new to kml but am familiar with postgis and perl and PHP. Is there a tutorial for the process of converting postgis data to kml? Where can I get started? Thanks for any help
You can use PostGIS to convert to KML directly:
SELECT ST_AsKML(geometry) from MyTable;
ST_AsKML is one of several output formats, including WKT, GML, GeoJSON, etc.
To show dynamic data in Google Earth, a common pattern is to use KML with a NetworkLink element. Have the link's viewRefreshMode equal to onStop and Google Earth will make requests (to a URL served by PHP, presumably) with bounding box parameters attached. Use the bounding box to query features in the PostGIS database, and return results as kml. This is great if you have lots and lots of features, but only want to retrieve those in the region the user is looking at.
Depending on the complexity of your application, you may also want to look at GeoDjango. (Familiarity with PostGIS is a big head start!)
You can get a textual representation of the spatial data from a Postgres DB using a text conversion function, like
SELECT AsText(MyGemoetry) from MyTable
then you parse the string, create your objects using various API functions - depending on the PostGIS geometry type - and append these object to the main GE plugin object in a DOM like way.
If you are familiar with JavaScript and have a fundamental knowledge of XML, a good start is http://code.google.com/apis/earth/documentation/reference/
Don't forget to specify unique ID's to your objects so you can find them later to drop/modify.
Maybe you can get some inspirations here, display the linked "locator.js" file and look at function PaintSubField(Coord) ... this is another way, bit crude but effective, avoiding to mess around with too many individual parent/child objects and structures
You also may want to consult sample applications and use the code playground for "rapid prototyping"
re "realtime" you need at least an event that you can link your generation/redraw routines to.
Good luck
MikeD

Resources