Converting a sharded Tesorflow Model - tensorflow.js

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

Related

Need help parsing through JSON Object in JMETER

I'm testing an application that calls one API, gets a bunch of work orders, then only the work order ID's are passed to another API to display on the page.
The format they need to be in is: {"workOrderIds":["12345","123456"]}
I'm using the JSON Extractor with the following Path Expressions:
$..workOrderNumber
then I'm using the JSR223 PostProcessor and using the following script:
props.put("workOrderNumber", "${workOrderNumber}";
The problem is, that its creating the object like so when I add the variable into the POST Request body of the second request:
{"workOrderIds":["12345, 123456"]}
essentially, I just need to make sure that each value has quotations, but not sure how to make this happen. Sorry if this seems simple, I'm fairly new to QA and have spent several hours trying to figure this out.
We cannot provide a comprehensive answer without seeing the source JSON, maybe it worth trying explicitly casting the filtering result to an Integer like:
vars.put('workOrderIds', new groovy.json.JsonBuilder(new groovy.json.JsonSlurper().parse(prev.getResponseData()).findResults { entry -> entry.workOrderNumber as int }).toPrettyString())
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

How to parse and play Blob/Binary data from database in Angular 5

In my Angular 5 application, I am retrieving data which is stored as VARBINARY(MAX) in SQL Server database. It looks like this in the database field: 0xFEA47E451A40AE4571E51F...
When I retrieve it from database using a GET call via .NET WebAPI, it is shown like this in console from my Angular app: aFwwbUYFjhvbv=bhBGVJHvchjhcbsHKfvHbbh...
I know the MIME type of this data (it is either MP3 or WAV). How can I parse/read this data in Angular 5 client and play it using an HTML <audio> component?
I have looked at several related solutions but none seem to be applicable due to one error or another, or perhaps there is a lack of understanding on my part.
My assumptions are that Blob data has the audio content which I can play. I have to convert it to a File first. This is what I am trying:
const file = new File([blobData], "audio.mp3")
this.audioSource = URL.createObjectURL(file)
And in the HTML, I assign audioSource as the source of an HTML5 component.
<audio [src]="audioSource" type="audio/mp3"></audio>
This results in a net::ERR_UNKNOWN_URL_SCHEME error.
I tried sanitizer.bypassSecurityTrustUrl(this.audioSource) as well but this doesn't work either. What am I doing wrong, and how can I get the intended effect?
please check this answer : https://stackoverflow.com/a/40329529/1160236
if you have blob data with correct binaries all you have to do is to create URL using URL.createObjectURL(blob) then pass it to the audio tag as a source. (check step-3)
if you don't have blob data with correct binaries you can create blob data as shown in step-2.
I have created an Angular example which uses DomSanitizer via a custom pipe.
<audio [src]="audioSource | safe:'url'" id="audio" controls #audioTag></audio>
Reference : https://stackoverflow.com/a/40329529/1160236
Angular implementation using reference : https://stackblitz.com/edit/angular-audio-blob
DomSanitizer example: https://medium.com/#swarnakishore/angular-safe-pipe-implementation-to-bypass-domsanitizer-stripping-out-content-c1bf0f1cc36b
I hope this will help. just remember all you need is valid blob data.

I need some help manipulating a string in Ruby

I have this string 'custom_controller'.
I need to get it to this 'CustomController'.
It's from the required file name and the class name inside is needed.
To cut to the chase, the code is here.
It is a project that comes from the Rack tutorials on Github. rack/rack/wiki/Tutorials
But rather than just name them custom.rb and class Custom, I want it more like a Rails app without requiring Rails or any of the gems that come with Rails except maybe Rack.
This is not a Rails app. This is not even a Sinatra or Padrino app. It's just a home brew web framework using Rack.
You can use plain ruby to build your own camelize method.
def camelize(string)
string.split('_').map(&:capitalize).join
end
This would also work:
"custom_controller".gsub(/_*([a-z]+)/i) {$1.capitalize}
And is closer to the way Rails handles this issue. I'd suggest you look at the Rails code as it also handles some variations on the simple case you quote. For example, how would you handle name spaced controllers 'foo/custom_controller'?
The desired result is just the camel case representation of the source string. You can try to use 'custom_controller'.camelize.
You could get it as 'CustomController' by doing following :
'custom_controller'.split('_').collect{|x| x.camelize}.join
If you want to use this as class you could do following :
'custom_controller'.split('_').collect{|x| x.camelize}.join.constantize
constantize is basically used to convert any string to class.
But I am not sure whether that works for controller. You can read more about it here
Read more about camelize here.

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'

Resources