I am trying to load a custom model from Firebase (The custom model is a .json file with three bin files).
The following code saves my custom model (Jupyter notebook, Python):
tfjs.converters.save_keras_model(model2, "model2")
Structure of the saved model:
The following code is using the loadLayersModel (ReactJS):
const link = {
model:
"https://firebasestorage.googleapis.com/v0/b/xxxxxxx.appspot.com/o/model2%2Fmodel.json?alt=media&token=f4b6be76-b760-496e-8983-7beda892f5a5",
};
const model = await loadLayersModel(link.model);
This is the following error (Chrome):
Uncaught (in promise) Error: Failed to parse model JSON of response from https://firebasestorage.googleapis.com/v0/b/xxxxxxxx.appspot.com/o/model2%2Fmodel.json?alt=media&token=f4b6be76-b760-496e-8983-7beda892f5a5. Please make sure the server is serving valid JSON for this request.
at HTTPRequest.load (http.ts:168:1)
at async loadLayersModelFromIOHandler (models.ts:293:1)
at async predictionModel (App.js:74:1)
These are my rules in firebase storage (Firebase storage):
I already tried to load a tflite model, but it gave me the same predictions over and over again. So I am trying to understand how to load in a json model from firebase.
Related
I have an API Gateway resource which calls a Dynamodb post request to query a table. I'm trying to call the API within my React app using Axios. The API is working, returning the data as expected (console log) but I'm getting errors if I try to use #aws-sdk/util-dynamodb (unmarshall) to convert the api data.items response into JSON and use within React.
./node_modules/#aws-sdk/util-dynamodb/dist-es/convertToNative.js 45:14 Module parse failed: Unexpected token (45:14)
Is there a way to use 'unmarshall' within React? Something like this:
useEffect(() => {
const getGoal = async () => {
try {
const response = await api.get(apiUrl)
setGoal(unmarshall(response.data.Items))
This works if I use a Lambda service, but I'm try to see if I can reduce my code.
While I'm not sure on the issue you are getting with unmarshall function, I would suggest using the DynamoDB Document Client which will return your data already unmarshalled.
The DynamoDB Document client simplifies working with items by abstracting the notion of attribute values. This abstraction annotates native JavaScript types supplied as input parameters, and converts annotated response data to native JavaScript types.
I have uploaded the model.json file of my tensorflow graph to a private repository on an AWS S3 bucket, and am now trying to load the graph with the loadGraphModel (alongside with the binary files of the weight manifest values, group1-shard1of1). Here's my code, which I run with node (I've kept the bucket path and signature keys private)
TFJSConverter = require('#tensorflow/tfjs-converter')
const MODEL_URL = "https://[BucketName].s3.amazonaws.com/[PathToModel]/model.json?[credentials]&[securitykey]";
global.fetch = require('node-fetch')
TFJSConverter.loadGraphModel(MODEL_URL)
However the loadGraphModel function looks for a model url ending with '.json'. If not, it looks for the full model url and checks for a weight manifest file called weights_manifest.json, with no signature. An error request then follows:
UnhandledPromiseRejectionWarning: Error: Request to https://[BucketName].s3.amazonaws.com/[PathToModel]/model.json?[credentials]&[securitykey],https://[BucketName].s3.amazonaws.com/[PathToModel]/weights_manifest.json failed with status code 403. Please verify this URL points to the model JSON of the model to load.
I've checked that the signed url actually works, is there a solution for signed urls?
Installed versions:
#tensorflow/tfjs-converter#1.1.2
node v10.15.3
Many thanks!
The correct library to use to load the model is tfjs and not tfjs-converter
let tf = require("#tensorflow/tfjs");
tf.loadGraphModel(MODEL_URL)
403 error is an authorization error response. Try to set the credentials in the request using requestInit of the object passed as parameter of loadGraphModel
This worked for me:
const fetch = require('node-fetch')
global.fetch = fetch
but you can also try:
const fetch = require('node-fetch')
tf.loadGraphModel(MODEL_URL, { fetchFunc: fetch } )
as described in the documentation:
https://js.tensorflow.org/api/latest/#loadGraphModel
I am trying to connect asp.net core web api(thats already connected to my local sqlserver and working fine) to my asp.net-mvc5 web app so when the controller is called it fetches the data from database using API
Now, this is how I'm trying to connect the api in my asp.net mvc project, shown below is homeController:
namespace AptitudeTest.Controllers
{
public class HomeController : Controller
{
string Baseurl = "http://localhost:51448";
public async Task<ActionResult> Index()
{
List<Teacher> teacher = new List<Teacher>();
//Teacher t1 = new Teacher();
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(Baseurl);
client.DefaultRequestHeaders.Clear();
//Define request data format
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//Sending request to find web api REST service resource GetAllEmployees using HttpClient
HttpResponseMessage Res = await client.GetAsync("api/Admin/Get");
//Checking the response is successful or not which is sent using HttpClient
if (Res.IsSuccessStatusCode)
{
//Storing the response details recieved from web api
var EmpResponse = Res.Content.ReadAsStringAsync().Result;
//Deserializing the response recieved from web api and storing into the Employee list
teacher = JsonConvert.DeserializeObject<List<Teacher>>(EmpResponse);
}
//returning the employee list to view
return View(teacher);
}
}
I expect it to return me teachers as json objects but this is the error im getting:
The model item passed into the dictionary is of type 'System.Collections.Generic.List1[AptitudeTest.Teacher]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[AptitudeTest.Models.Teacher]'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Collections.Generic.List1[AptitudeTest.Teacher]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[AptitudeTest.Models.Teacher]'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
The error you are getting is:
The model item passed into the dictionary is of type 'System.Collections.Generic.List1[AptitudeTest.Teacher]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[AptitudeTest.Models.Teacher]'.
which means your view expects different model object as input while the passed object is of different type. It looks like that you have in view defined model as:
IEnumerable<Teacher>
while you are returning a List<Teacher>. Either change in view it to List<Teacher> like:
#model List<Teacher>
or return an IEnumerable<Teacher> object from the controller action.
for that you can write the following:
IEnumerable<Teacher> teachers = teacher;
return View(teachers );
Either way you should be able to resolve the error and keep moving.
EDIT:
didn't noticed that there are two different classes in different namespace, one is AptitudeTest.Teacher and other is AptitudeTest.Models.Teacher. the class which we have defined the view should be same which is passed from the action method. Right now there are two classes each in different namespace.
My Problem:
I am attempting to fill a datastore model in GAE that contains an ndb.Structured Property() using a 'POST' request.
This question has been asked recently but not answered (How to “POST” ndb.StructuredProperty?)
I have the following two models:
class Check(EndpointsModel):
this = ndb.StringProperty()
that = ndb.StringProperty()
class CheckMessage(EndpointsModel):
check = ndb.StructuredProperty(Check)
I'm trying to post this data:
{
check:
{
"this":"test",
"that":"test"
}
}
with the following API request:
#CheckMessage.method(name='check_insert',path='check/insert',http_method='POST')
def check_insert(self,request):
print(request)
Upon posting from the client I receive the following error:
AttributeError: 'Check' object has no attribute '_Message__decoded_fields'
The Issue:
From my very high-level understanding of the endpoints-proto-datastore module it seems that when the json is being decoded and saved onto the incoming message (utils.py line 431) it's not checking for structured/localstructured properties and saving their keys as well which is all fine and dandy until FromValue (ndb/model.py line 115) checks for instances of structured properties and attempts to recursively convert the structured property from the protorpc message into a model entity (which needs the _Message__decoded_fields).
Sasxa (see the link above) had found a nifty little workaround to this issue by using an EndpointsAliasProperty converted to a ProtoRPC message class to bypass endpoints-proto-datastore's automatic conversion of the structuredproperty into its associated model entity, however this workaround had some side effects that made what I was trying to do difficult.
The Question:
Does anyone know how to correctly fill a datastore model containing a StructuredProperty using a 'POST' request, and are there any working examples of this available?
In the dev environment for my React app, I have a set of public/private keys that I need to access an API. I'd like to ideally put these keys into their own file for gitignore purposes, but i'm not having luck with my code as shown below.
my helpers.jsx file is where the API data is called via lightweight AJAX add-on, and I have the actual keys in the require declarations area:
var API_KEY = require('./keys.jsx');
var PRIV_KEY = require('./keys.jsx');
Summarily, my keys.jsx file (stored in the same subfolder as the helpers.jsx) consists of the following:
module.exports = {
API_KEY:'myactualpublickey',
PRIV_KEY:'myactualprivatekey'
};
However, my app does not like this set up, as I get an "Failed to load resource: the server responded with a status of 401 (Unauthorized)” error message and the API call isn't successful because the necessary keys are not included.
When I replace the require('./keys.jsx'); in the helpers.jsx file with the actual keys, the API call works fine.
Any help or guidance would be most appreciated. Thanks.
You're exporting an object with properties called API_KEY and PRIV_KEY, so try this:
var API_KEY = require('./keys.jsx').API_KEY;
var PRIV_KEY = require('./keys.jsx').PRIV_KEY;