I have a trained model, saved it with const saveResult = await model.save('localstorage://my-model-1');.
Now I want to reload it and use it again. So I want to do something like this:
async function loadModel() {
let myModel = tf.sequential();
myModel = await model.save('downloads://my-model-1')
console.log(myModel);
let outputs = myModel.predict([
tf.tensor2d([[0, 0, 1]])
]);
outputs.print();
}
But It seems like model.save returns a modelArtifactsInfo. So how could I create a model from this Object?
I followed this tutorial but they don't really explain that.
is that even possible?
In the tutorial it says it all:
You just have to call tf.loadModel with your savehandle which returns a promise which resolves to the loaded model or throws an error. In your case the handle would be 'localstorage://my-model-1'.
const model = await tf.loadModel('localstorage://my-model-1');
Related
I am using the following code and my aim is to get the data from the data section of the PromiseResult object of the returned Promise. I am using the following code:
const promiseComment = axios.post(`${BASE_URL}/api/addComment/`, data, getDefaultHeaders());
let allPromises = []
allPromises.push(promiseComment)
Promise.all([allPromises])
.then(function (values) {
console.log(values[0][0]);
});
When I console the values, I get the following response, what I need is the data section from the response which I marked in the following image.
Thanks in advance
you need to resolve the promise inside
const promiseComment = axios.post(`${BASE_URL}/api/addComment/`, data, getDefaultHeaders());
let allPromises = []
allPromises.push(promiseComment)
Promise.all([allPromises])
.then(values=>values).then(obj=>console.log(object.data));
I've been trying to save data from my form in my MongoDB for some time.
I also get a response from the database.
See also: create object in mongo db api onclick sending form
Unfortunately there are not enough tutorials in my mother tongue and I don't seem to understand everything in English.
I've tried some of the documentation, but I always fail.
What is missing in my webhook function so that the form data can be stored?
exports = function(payload) {
const mongodb = context.services.get("mongodb-atlas");
const mycollection = mongodb.db("created_notifications").collection("dpvn_collection");
return mycollection.find({}).limit(10).toArray();
};
The Webhookfunction was totally wrong.
READ THE DOCUMENTATION FIRST
exports = function(payload, response) {
const mongodb = context.services.get("mongodb-atlas");
const requestLogs = mongodb.db("created_notifications").collection("dpvn_collection");
requestLogs.insertOne({
body: EJSON.parse(payload.body.text()),
query: payload.query
}).then(result => {
})
};
I'm sending an AJAX request to an internal PHP and receiving back an object. The object has properties of "data" and "status", yet when I try to access them, it does not return anything. How can I show each property separately?
For reference, the returned obj array is:
{"data:[{"tagId":"8787","tagDescription":"001","tagMin":"0","tagMax":"100"},{"tagId":"8729","tagDescription":"1","tagMin":"44","tagMax":"555"}]
function GetAll() {
var PostRequest ={};
PostRequest['tagId']= 'all';
$.post('php here',PostRequest,ShowAllTags);
}
function ShowAllTags( responseData, responseStatus ) {
console.log(responseStatus);
var tagData = {};
tagData = responseData;
console.log(tagData['data']);
}
So according to the above comment mention by me, The problem is with json object, in response.
So first of all fix that,
Generic solution of this problem will be;
var obj = [{"tagId":"8787","tagDescription":"001","tagMin":"0","tagMax":"100"},{"tagId":"8729","tagDescription":"1","tagMin":"44","tagMax":"555"}];
obj.forEach(function(value, index){console.log(value.tagId)});
This might help, how to get value of each property
I have a service that does an http request to save some data. When the data comes from the backend I am doing some manipulation on the data and then return it so that controllers can use them. Something like:
public savePerson = (person: Model.IPerson): ng.IPromise<Model.IMiniPerson> => {
return this.api.persons.save({}, person).then((savedPerson) => {
this.enrichWithLookups(savedPerson);
var miniPerson = new Model.MiniPerson();
angular.extend(miniPerson, savedPerson);
miniPerson.afterLoad();
this.persons.unshift(miniPerson);
this.notifyOfChanges();
return miniPerson;
});
}
In order to clean up the code a bit and make it more testable I wanted to remove the private manipulation functions into decorating/intercepting services. Problem is I do not know how to hook on the promise data before the success function is executed and after it is returned.
For example enrichWithLookups must be applied first just after the data arrives and not after the miniPerson is returned.
you can create a local promise and call the "resolve" method when you have completed your operations on the http response. Look at the code down here:
public savePerson = (person: Model.IPerson): ng.IPromise<Model.IMiniPerson> => {
var waiter = $q.defer();
this.api.persons.save({}, person).then((savedPerson) => {
this.enrichWithLookups(savedPerson);
var miniPerson = new Model.MiniPerson();
angular.extend(miniPerson, savedPerson);
miniPerson.afterLoad();
this.persons.unshift(miniPerson);
this.notifyOfChanges();
waiter.resolve(miniPerson);
});
return waiter.promise;
}
I've wrote the code directly with angularjs, but I think that you can easily adapt it to fit your needs.
Bye.
Adding Backbone to a Rails app, I created a post model inside an app namespace like this
var app = {
this.models.post = new app.Models.Post();
In the router, I created the following route
"posts/:id": "postDetails"
When I navigate to /posts/4, I'm getting an Uncaught TypeError: object is not a function error when I try to call fetch on the model like this
postDetails: function (id) {
console.log(id);
var post = new app.models.post({id: id});
this.post.fetch({
success: function (data) {
$('#content').html(new PostView({model: data}).render().el);
}
});
}
According to the Backbone docs http://backbonejs.org/#Model-fetch, I should be able to call fetch on a model to retrieve the data from the server. Why does Backbone think I'm treating an object like a function?
You're doing this:
this.models.post = new app.Models.Post();
to, presumably, set app.models.post to an instance of the app.Models.Post model. Then you try to do this:
var post = new app.models.post({id: id});
But you can only use the new operator on a function:
new constructor[([arguments])]
Parameters
constructor
A function that specifies the type of the object instance.
You probably want to say:
var post = new app.Models.Post({ id: id });
or something similar.
The problem is you've declared post as a local variable var post, but then tried to access it as a member this.post. You need either this:
this.post = new app.models.post({id: id});
this.post.fetch({ ...
Or this:
var post = new app.models.post({id: id});
post.fetch({ ...
(The difference being that a local variable var post is declared in transient scope and thrown away after postDetails completes; while instance variable this.post gets added to the Router object and will typically live for the whole lifetime of the application.)