Register model from pipeline (CLI v2) - azure-machine-learning-service

I have a pipeline where I do training for a model and at the end I'd like to register that model but I can't find any information on this.
Here's how my pipeline looks now:
type: pipeline_job
compute:
target: azureml:gpu-cluster
inputs:
input_images:
data:
datastore: azureml:dualcam
path: /image-20210701*
jobs:
training:
type: component_job
component: file:./components/training.yml
inputs:
input_images: inputs.input_images

You can upload it to the run using upload_file and then register the model.
Uploading the model into the run history record before trying to register the model:
run.upload_file("outputs/my_model.pickle", "outputs/my_model.pickle")
print(run.get_file_names())
print(os.getcwd())
model = run.register_model(model_name='simtemp', model_path="outputs/{}".format(model_file_name))
Please follow the document for run.

Related

How to conditionally run collection of stages in mongoose aggregate pipeline?

I have a used mongoose aggregate pipeline with many stages in one of my api endpoints. In that pipeline there is a $unwind stage and multiple $lookup stages that must only run if images array in document in not empty. How can I setup the pipeline such that a select few stages may or may not run based on a condition derived from a field within the documents?
Thank you for reading.
For reference, here is a sample document.
{
_id: "6151387333f8e9001ff92429",
title: "Boost Your Car With These Tips",
description: "Follows these steps to get the most out of your car",
images: [
{
image: "5ebac534954b54139806c112",
caption: "Riding Ferreri",
credit: "5ebac534954b54139806c112"
},
{
image: "4ebac534954b54139806c142",
caption: "Motor Garage",
credit: "6ebac534954b54139806c11e"
},
]
}

How to reference generated Prisma schema in my schema.graphql file for a query that filters by id

Trying to add a Query that filters by the unique Id of this object.
Query.js
async function getAbility (root, args, context, info) {
return await context.prisma.ability({
where : {id : args.abilityId}
}, info)
}
This is also defined in my schema.graphql file.
getAbility(where: AbilityWhereUniqueInput) : Ability
I recognize that AbilityWhereUniqueInput comes from the schema generation done with the Prisma CLI however I am unsure how to reference it for the schema.graphql file.
I have attempted to add this at the top of the file:
# import * from './generated/prisma-client/prisma-schema'
But whenever I try to run the application, it is saying that it encounters an unexpected character '.', referring to the first part of the file path i'm providing for the import.
Other Relevant Declarations:
schema.graphql
type Ability {
id: ID!
name: String!
description: String!
imagePath: String!
}
prisma.yml
# Specifies the HTTP endpoint of your Prisma API (deployed to a Prisma Demo server).
endpoint: https://eu1.prisma.sh/public-cookiearm-769/exp-graphql-subscription/dev
# Defines your models, each model is mapped to the database as a table.
datamodel: datamodel.prisma
# Specifies the language and directory for the generated Prisma client.
generate:
- generator: javascript-client
output: ../src/generated/prisma-client
- generator: graphql-schema
output: ../src/generated/prisma.graphql
# Seed your service with initial data based on `seed.graphql`.
seed:
import: seed.graphql
# Ensures Prisma client is re-generated after a datamodel change.
hooks:
post-deploy:
- prisma generate
# If specified, the `secret` must be used to generate a JWT which is attached
# to the `Authorization` header of HTTP requests made against the Prisma API.
# Info: https://www.prisma.io/docs/prisma-graphql-api/reference/authentication-ghd4/
# secret: mysecret123
Here you see I'm generating two files. One for prisma client and other for importing types in schema.graphql.
schema.graphql
# import * from './generated/prisma.graphql'
type Query {
feed: [Post!]!
drafts: [Post!]!
post(id: ID!): Post
}
type Mutation {
createDraft(title: String!, content: String): Post
editPost(id: String!, data: PostUpdateInput!): Post
deletePost(id: ID!): Post
publish(id: ID!): Post
}
type Subscription {
post: Post!
}
type Post {
id: ID!
published: Boolean!
title: String!
content: String!
}
See this line
# import * from './generated/prisma.graphql'
Now I can use PostUpdateInput in schema.graphql
Make sure that you changes the path following yours.
Make sure the imported generated schema is .graphql extension, because you can't import non-graphql files in a graphql file.

'myTable' is not associated to Model

I'm working on an express sequelize project.
I've got an issue with sequelize.
I've got a simply schema like the documentation says:
class Task extends Model {}
Task.init({ title: Sequelize.STRING }, { sequelize, modelName: 'task' });
class User extends Model {}
User.init({ username: Sequelize.STRING }, { sequelize, modelName: 'user' });
User.hasMany(Task); // Will add userId to Task model
Task.belongsTo(User); // Will also add userId to Task model
But when I'm querying with include
sequelize.models['task'].findAll({include:[{all:true}]});
I'm facing to some issues:
The first :
this._getIncludedAssociation is not a function
Here is the github source origin code : https://github.com/sequelize/sequelize/blob/master/lib/model.js#L615
I just change this to Model to check.
This error is gone away, but a second (linked with the first, because I changed the behaviour), appears
User is not associated to Model
But It should say User is not associated to Task
(github of error: https://github.com/sequelize/sequelize/blob/master/lib/model.js#L711)
It's like the class Model wasn't instanciate...
What could be bad in my code ? Maybe the fact to call the model by sequelize.models[modelName] ?? I'm struggling with this for a long time...
Thanks.
More Infos :
Sequelize Version : ^5.7.0
Architecture :
At the application launch, all my models are store in a custom Database class stored in my process.
Inside any controller, I call a repository class with for exemple a method like the following where the wanted model is accessible via this.model:
findAll(options, force = false) {
let data = this.performExtraOptions(options);
data.paranoid = force;
if (this.isDebug) {
this.req.debug.addDatabaseCall('Table ' + this.model.getTableName() + ' findAll', data);
}
return this.model.findAll(data);
}
When I inspect with Chrome Debugger, the model is show like this :
const model = class extends Model {};
Ok.
In reading the sequelize code, I found that the options.model is required inside the algo.
The problem was that I sent the model too in the query options, but as the model name (string).
The algo, transform the option.model as the instance object of Model to make the process.
So I just have to rename my variable passed as query options.
This line of code was the problem :
https://github.com/sequelize/sequelize/blob/master/lib/model.js#L493
if (!options.model) options.model = this;

How to show uploaded image in Keystonejs back-end

Very similar to problem here but I'm not using S3 files and the info in that link is somewhat dated (hasn't been updated since github issues linked from question above were closed).
My question is about how to get a preview of an uploaded image in Keystonejs's admin back-end. Although it seems like it's a hacky fix (editing keystone files as suggested in link above) I'm wondering if there's other options.
Although they've added support for S3 files and Types.CloudinaryImage is supported I can't get a preview of the uploaded image when it's just an uploaded image since Keystone treats it as an arbitrary file (not an image).
Screenshot: as you can see Keystone just shows the filename (highlighted in red).
Model is set up as follows:
var keystone = require('keystone');
var Types = keystone.Field.Types;
/**
* Image Upload Model
* ==================
* A database model for uploading images to the local file system
*/
var ImageUpload = new keystone.List('ImageUpload');
var myStorage = new keystone.Storage({
adapter: keystone.Storage.Adapters.FS,
fs: {
path: keystone.expandPath('./public/uploads/images'),
publicPath: '/public/uploads/images',
}
});
ImageUpload.add({
name: { type: Types.Key, index: true },
image: {
type: Types.File,
storage: myStorage
},
createdTimeStamp: { type: String },
url: { type: String }
});
ImageUpload.defaultColumns = 'url, createdTimeStamp, image';
ImageUpload.register();
As far as I get it the only way - is to implement this by yourself.
It's not so scary as it my look but you should spend a lot of time to do that.
You need to investigate how for now different filed types are showed in admin page - for that you should take a look at template for admin page which is provided with KeystoneJS already (path: node_modules\keystone\admin\server\templates)
After that you might want to look for (path: node_modules\keystone\fields)
You might be interested in TYPES subfolder - cause there different field types rules
So your goal is to find corresponding field description (for your ImageUpload FileSystem model) or create a new one with img tag to show picture from url
I think File type is that what you are looking for - \node_modules\keystone\fields\types\file
Image previews are now possible in the latest master branch of keystone (see https://github.com/keystonejs/keystone/pull/4509). At the moment you need to depend on the git version of keystone, so put this in your package.json and run npm install:
"keystone": "https://github.com/keystonejs/keystone.git"
In your model, specify thumb: true on the image field in question. You also need the url property in the schema. For example:
const storage = new keystone.Storage({
adapter: keystone.Storage.Adapters.FS,
fs: {
path: keystone.expandPath('./uploads/images'),
publicPath: '/images/'
},
schema: {
url: true,
}
})
ImageUpload.add({
name: { type: Types.Key, index: true },
image: {
type: Types.File,
storage: myStorage,
thumb: true
},
createdTimeStamp: { type: String }
});
The admin UI should now show a small preview of the image and a link to it.

Create model in model

I'm new to strongloop and look at documentation and samples but never see my problem as desired.
I'v two models, sentence.js and log.js and making post request a sentence from mobile app to rest-api, for example
Model sentence.js (dont want save to db this model, only for parsing and creating log model)
{
name: 'sentence',
type: 'string'
}
Model log.js
{ name: 'lat', type: 'string' },
{ name: 'lng', type: 'string' }
[HTTP POST] myserver/api/sentence?d=$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
A model has triggered methods, e.g, afterInitialize, beforeValidate , beforeSave. Now, which triggered method or any other scope correct and best for parsing sentence model and creating log model ?
Thanks !
In your case the best place is
Sentence.beforeRemote('create', function(ctx, sentence, next){
console.log(ctx.req.body);
next()
})
Also Model hook Sentence.afterInitialize and Model Event Sentence.on('set') are available, but will be called in some extra cases.
(Note that in my case I would use remote hooks and only ONE Log model.)

Resources