-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathupdate_model_config_v4.js
127 lines (118 loc) · 4.86 KB
/
update_model_config_v4.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const { ClarifaiStub, grpc } = require('clarifai-nodejs-grpc');
// Initialize the gRPC client
const stub = ClarifaiStub.grpc();
const metadata = new grpc.Metadata();
const apiKey = process.env.new_clarifai_key.trim().replace(/[^a-zA-Z0-9]/g, '');
metadata.set('authorization', `Key ${apiKey}`);
async function updateModel() {
try {
const modelId = 'catsdogstest';
console.log('Updating model configuration...');
// Update model with proper configuration using PatchModels
const patchResponse = await new Promise((resolve, reject) => {
stub.PatchModels(
{
action: 'overwrite',
models: [{
id: modelId,
name: 'Cats and Dogs Classifier',
model_type_id: 'visual-classifier',
output_info: {
message: 'Classification model for cats and dogs',
type: 'concept',
type_ext: 'concept',
data: {
concepts: [
{ id: 'cats', name: 'cats' },
{ id: 'dogs', name: 'dogs' }
]
},
output_config: {
concepts_mutually_exclusive: true,
closed_environment: true
}
}
}]
},
metadata,
(err, response) => {
if (err) {
console.error('Error updating model:', err);
reject(err);
} else {
console.log('Model update response:', JSON.stringify(response, null, 2));
resolve(response);
}
}
);
});
// Verify the updated model
const verifyResponse = await new Promise((resolve, reject) => {
stub.GetModel(
{ model_id: modelId },
metadata,
(err, response) => {
if (err) {
console.error('Error verifying model:', err);
reject(err);
} else {
console.log('Updated model structure:', JSON.stringify(response, null, 2));
resolve(response);
}
}
);
});
if (verifyResponse.model.output_info) {
console.log('Model update successful - output_info is properly configured');
// Try creating a model version
console.log('Attempting to create model version...');
const versionResponse = await new Promise((resolve, reject) => {
const versionId = `v${Date.now()}`;
stub.PostModelVersions(
{
model_id: modelId,
version: {
id: versionId,
output_info: {
data: {
concepts: [
{ id: 'cats', name: 'cats' },
{ id: 'dogs', name: 'dogs' }
]
},
output_config: {
concepts_mutually_exclusive: true,
closed_environment: true
}
},
train_info: {
params: {
template: 'classification_base',
epochs: 5,
batch_size: 32,
learning_rate: 0.001
}
}
}
},
metadata,
(err, response) => {
if (err) {
console.error('Error creating version:', err);
reject(err);
} else {
console.log('Version creation response:', JSON.stringify(response, null, 2));
resolve(response);
}
}
);
});
} else {
console.log('Model update failed - output_info is not configured');
}
console.log('Model update process complete');
} catch (error) {
console.error('Update failed:', error);
}
}
updateModel();