Typescript and Tensorflow.js models - tensorflow.js

In the Blazeface 1 source file face.ts there is a class BlazeFaceModel with the constructor model: tfconv.GraphModel. I need to call this model from my index.ts file. In the official Blazeface demo index.js this is done by let model;.
For the sake of writing strict Typescript, how should I declare the type of model in my Typescript file? I could import
import * as tfconv from '#tensorflow/tfjs-converter';
and set const model: tfconv.Graphmodel, but how "valid" is that approach?

Related

Base Class vs Extended Classes

I'm a new learner, I'm practicing the base and child classes. My question is how do we decide which class should be instantiated, extended or the Baseclass?
Thanks in advance
package MavenProject2Package2;
import org.testng.annotations.Test;
import MavenProject2Package.JavaTesting;
public class JavaTesting2 extends JavaTesting
{
#Test
public void f1()
{
JavaTesting a1 = new JavaTesting();
System.out.println(a1.msg);
JavaTesting2 a2 = new JavaTesting2();
System.out.println(a2.msg);
}
}
Base class - it's a class which you should be extending from. - eg - superclass.
In superclass you may put some general fields and methods, which are used across your web app. For example, locators for header as well as footer items, because they are the same for all the pages (mostly).

Why OWLReasoner.getSubclasses(...) returns http://www.w3.org/2002/07/owl#Nothing?

Here is a piece of my ontology subclasses request, using JAVA-7 and owlapi library:
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.owlapi.reasoner.ConsoleProgressMonitor;
import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration;
...
...
OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(myconfiguration);
OWLReasoner reasoner = reasonerFactory.createReasoner(myontology, config);
Set<OWLClass> subclasses = reasoner.getSubClasses(myClazz, true).getFlattened();
Here is my question:
Why does the subclasses, what OWLReasoner.getSubClasses(...) method returns, contains all the subclasses of myClazz, but always also adds the OWLClass with URI http://www.w3.org/2002/07/owl#Nothing? I have defined nowhere this class.
Thanks in advance.
owl:Nothing is the class defined to be subclass of all classes in OWL, so it's included as subclass of all satisfiable classes (it is equivalent to all unsatisfiable classes).
To skip it during iterations, Node has a getEntitiesMinusBottom() method that will skip owl:Nothing.
At w3.org owl semantics, you can find more info about the owl:Nothing class: https://www.w3.org/TR/2004/REC-owl-semantics-20040210/#owl_Nothing

How to deal with spurious type script error: types of property $timeout of types base class and derived class are incompatible?

Since upgrading to TypeScript 1.6, I've been getting what appears to be a spurious error with all my ng.Types:
Typescript 1.6 class 'derivedClass' cannot extend class 'baseClass':
types of property $timeout of types base class and derived class are
incompatible
Here's the code sample:
module app.Test {
class derivedClass extends baseClass {
// Notice there's nothing in the derived class
}
class baseClass {
constructor(timeout: ng.ITimeoutService, val1: string, otherVal: ng.ILogService) {
var vm = this;
vm.$timeout = timeout;
vm.someValue = val1;
vm.otherValue = otherVal;
}
$timeout: ng.ITimeoutService; // angular.ITimeoutService works
someValue: string;
otherValue: ng.ILogService;
}
}
angular.ITimeoutService works, or adding import ng= angular; in my modules also works. This didn't used to be an issue in the previous versions of Typescript.
Is it best practice to repeat the alias (eg: import ng = angular) in each module before using it, even though that's already done in the angular.d.ts?
Is it best practice to repeat the alias (eg: import ng = angular) in each module before using it, even though that's already done in the angular.d.ts
NO. The error is happening probably because you have done this.
The code you have posted works fine by default:

CakePHP 3.0 vendor class not found

I'm adding an external class to a cake 3.0 app by putting it to /vendor/name folder and requiring it from a component like this:
require_once( $_SERVER['DOCUMENT_ROOT'].'/project/vendor/external/testClass.php');
But when I try to getInstance(); of a class - I get an error
Class 'App\Controller\Component\Test_Class' not found
I am calling this from a component (thus the \Controller\Component).
What is it that i'm doing wrong?
CakePHP 3.0 uses namespaces. So use proper namespace for your vendor class or if it's not using namespaces prefix the class name with backslash when using it.
E.g. $object = new \Test_Class();.

Django TypeError when trying to use custom base ModelForm or custom error_class

I wanted to have for error_class rendering in forms. I saw this definition and put it into a file in my app directory:
from django.forms.util import ErrorList
class DivErrorList(ErrorList):
def __unicode__(self):
return self.as_divs()
def as_divs(self):
if not self: return u''
return u'<div class="errorlist">%s</div>' % \
''.join([u'<div class="error">%s</div>' % e for e in self])
But, when I try to use it in my view:
from sporty import DivErrorList
...
form = LocationForm(request.POST or None, error_class=DivErrorList)
if form.is_valid():
I get this error, when submitting the form with an error:
TypeError: 'module' object is not callable
/usr/local/lib/python2.7/dist-packages/django/forms/forms.py in _clean_fields, line 293.
This is at the form.is_valid() line. If I don't use the error_class, it works fine (only without the desired .
Next, I tried to instead, create a base ModelForm class that uses the DivErrorList in my app directory:
from django.forms import ModelForm
from sporty import DivErrorList
class MyModelForm(ModelForm):
def __init__(self, *args, **kwargs):
kwargs_new = {'error_class': DivErrorList}
kwargs_new.update(kwargs)
super(MyModelForm, self).__init__(*args, **kwargs_new)
and then I defined my ModelForm based on that class and no longer used the error_class argument on the form creation:
from sporty import MyModelForm
from sporty.models import Location
class LocationForm(MyModelForm):
class Meta:
model = Location
Now, when I try to even view the form (not submitting it with any data), I get this error:
TypeError: Error when calling the metaclass bases module.init() takes at most 2 arguments (3 given)
/home/pcm/workspace/sportscaster/sporty/forms.py in , line 5
I'm at a loss on both of these. Any ideas? I'd prefer the latter, as all my forms will want to use for error reporting (I'd like to actually render the form as divs too, as some point.
Googling around, I found a discussion on type errors and metaclass bases. The issue was that I had a class, MyModelForm, in a file MyModelForm.py, and was then importing the module attempting to use it like a class:
from sporty import MyModelForm
The solution was to place MyModelForm class into a file modelforms.py and do:
from sporty.modelforms import MyModelForm
I did the same with DivErrorList, placing the class in the modelforms.py file.

Resources