@@ -13,7 +13,7 @@ import { observeChild } from 'platform/desktop/backend/native/processManager';
13
13
14
14
import { MultiType , stereoPipelineMarker , multiCamPipelineMarkers } from 'dive-common/constants' ;
15
15
import * as common from './common' ;
16
- import { jobFileEchoMiddleware , createWorkingDirectory } from './utils' ;
16
+ import { jobFileEchoMiddleware , createWorkingDirectory , createCustomWorkingDirectory } from './utils' ;
17
17
import {
18
18
getMultiCamImageFiles , getMultiCamVideoPath ,
19
19
writeMultiCamStereoPipelineArgs ,
@@ -242,39 +242,55 @@ async function exportTrainedPipeline(settings: Settings,
242
242
throw new Error ( "Your pipeline has no trained weights (yolo.weights is missing)" ) ;
243
243
}
244
244
245
+ const jobWorkDir = await createCustomWorkingDirectory ( settings , 'OnnxExport' , pipeline . name ) ;
246
+
247
+ const converterOutput = npath . join ( jobWorkDir , 'model.onnx' ) ;
248
+ const joblog = npath . join ( jobWorkDir , 'runlog.txt' ) ;
249
+
245
250
const command = [
246
251
`${ viameConstants . setupScriptAbs } &&` ,
247
252
`"${ viameConstants . kwiverExe } " runner ${ exportPipelinePath } ` ,
248
253
`-s "onnx_convert:model_path=${ weightsPath } "` ,
249
- `-s "onnx_convert:onnx_model_prefix=${ path } "` ,
254
+ `-s "onnx_convert:onnx_model_prefix=${ converterOutput } "` ,
250
255
] ;
251
256
252
257
const job = observeChild ( spawn ( command . join ( ' ' ) , {
253
258
shell : viameConstants . shell ,
254
- cwd : undefined ,
259
+ cwd : jobWorkDir ,
255
260
} ) ) ;
256
261
257
262
const jobBase : DesktopJob = {
258
- key : `pipeline_${ job . pid } ` ,
263
+ key : `pipeline_${ job . pid } _ ${ jobWorkDir } ` ,
259
264
command : command . join ( ' ' ) ,
260
265
jobType : 'export' ,
261
266
pid : job . pid ,
262
267
args : exportTrainedPipelineArgs ,
263
268
title : `${ exportTrainedPipelineArgs . pipeline . name } to ONNX` ,
269
+ workingDir : jobWorkDir ,
264
270
datasetIds : [ ] ,
265
271
exitCode : job . exitCode ,
266
272
startTime : new Date ( ) ,
267
273
} ;
268
274
275
+ fs . writeFile ( npath . join ( jobWorkDir , DiveJobManifestName ) , JSON . stringify ( jobBase , null , 2 ) ) ;
276
+
269
277
updater ( {
270
278
...jobBase ,
271
279
body : [ '' ] ,
272
280
} ) ;
273
281
274
- job . stdout . on ( 'data' , jobFileEchoMiddleware ( jobBase , updater ) ) ;
275
- job . stderr . on ( 'data' , jobFileEchoMiddleware ( jobBase , updater ) ) ;
282
+ job . stdout . on ( 'data' , jobFileEchoMiddleware ( jobBase , updater , joblog ) ) ;
283
+ job . stderr . on ( 'data' , jobFileEchoMiddleware ( jobBase , updater , joblog ) ) ;
276
284
277
285
job . on ( 'exit' , async ( code ) => {
286
+ if ( code === 0 ) {
287
+ if ( fs . existsSync ( converterOutput ) ) {
288
+ // We move instead of copying because .onnx files can be huge
289
+ fs . moveSync ( converterOutput , path ) ;
290
+ } else {
291
+ console . error ( "An error occured while creating the ONNX file." ) ;
292
+ }
293
+ }
278
294
updater ( {
279
295
...jobBase ,
280
296
body : [ '' ] ,
0 commit comments