refactor(log): use zap logger
This commit is contained in:
parent
456f327788
commit
0a1a189cfa
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/s3/types"
|
"github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||||
"github.com/cyrilix/robocar-tools/pkg/awsutils"
|
"github.com/cyrilix/robocar-tools/pkg/awsutils"
|
||||||
"log"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ListArchives(ctx context.Context, bucket string) error {
|
func ListArchives(ctx context.Context, bucket string) error {
|
||||||
@ -31,7 +31,7 @@ func (t Training) UploadArchive(ctx context.Context, archive []byte) error {
|
|||||||
client := s3.NewFromConfig(t.config)
|
client := s3.NewFromConfig(t.config)
|
||||||
key := aws.String("input/data/train/train.zip")
|
key := aws.String("input/data/train/train.zip")
|
||||||
|
|
||||||
log.Printf("upload archive to bucket '%s/%s'\n", t.bucketName, *key)
|
zap.S().Infof("upload archive to bucket '%s/%s'", t.bucketName, *key)
|
||||||
_, err := client.PutObject(
|
_, err := client.PutObject(
|
||||||
ctx,
|
ctx,
|
||||||
&s3.PutObjectInput{
|
&s3.PutObjectInput{
|
||||||
@ -43,6 +43,6 @@ func (t Training) UploadArchive(ctx context.Context, archive []byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to upload archive: %w", err)
|
return fmt.Errorf("unable to upload archive: %w", err)
|
||||||
}
|
}
|
||||||
log.Println("archive uploaded")
|
zap.S().Info("archive uploaded")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/cyrilix/robocar-tools/pkg/awsutils"
|
"github.com/cyrilix/robocar-tools/pkg/awsutils"
|
||||||
"github.com/cyrilix/robocar-tools/pkg/data"
|
"github.com/cyrilix/robocar-tools/pkg/data"
|
||||||
"github.com/cyrilix/robocar-tools/pkg/models"
|
"github.com/cyrilix/robocar-tools/pkg/models"
|
||||||
"log"
|
"go.uber.org/zap"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -36,18 +36,19 @@ type Training struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Training) TrainDir(ctx context.Context, jobName, basedir string, imgHeight, imgWidth int, sliceSize int, withFlipImage bool, outputModelFile string, enableSpotTraining bool) error {
|
func (t *Training) TrainDir(ctx context.Context, jobName, basedir string, imgHeight, imgWidth int, sliceSize int, withFlipImage bool, outputModelFile string, enableSpotTraining bool) error {
|
||||||
log.Printf("run training with data from %s\n", basedir)
|
l := zap.S()
|
||||||
|
l.Infof("run training with data from %s", basedir)
|
||||||
archive, err := data.BuildArchive(basedir, sliceSize, withFlipImage)
|
archive, err := data.BuildArchive(basedir, sliceSize, withFlipImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to build data archive: %w", err)
|
return fmt.Errorf("unable to build data archive: %w", err)
|
||||||
}
|
}
|
||||||
log.Println("")
|
l.Info("")
|
||||||
|
|
||||||
err = t.UploadArchive(ctx, archive)
|
err = t.UploadArchive(ctx, archive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to upload data arrchive: %w", err)
|
return fmt.Errorf("unable to upload data arrchive: %w", err)
|
||||||
}
|
}
|
||||||
log.Println("")
|
l.Info("")
|
||||||
|
|
||||||
err = t.runTraining(
|
err = t.runTraining(
|
||||||
ctx,
|
ctx,
|
||||||
@ -162,17 +163,17 @@ func (t *Training) runTraining(ctx context.Context, jobName string, slideSize in
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("unable to get status from ob %v: %v\n", jobOutput.TrainingJobArn, err)
|
l.Infof("unable to get status from ob %v: %v", jobOutput.TrainingJobArn, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch status.TrainingJobStatus {
|
switch status.TrainingJobStatus {
|
||||||
case types.TrainingJobStatusInProgress:
|
case types.TrainingJobStatusInProgress:
|
||||||
log.Printf("job in progress: %v - %v - %v\n", status.TrainingJobStatus, status.SecondaryStatus, *status.SecondaryStatusTransitions[len(status.SecondaryStatusTransitions) - 1].StatusMessage)
|
l.Infof("job in progress: %v - %v - %v", status.TrainingJobStatus, status.SecondaryStatus, *status.SecondaryStatusTransitions[len(status.SecondaryStatusTransitions) - 1].StatusMessage)
|
||||||
continue
|
continue
|
||||||
case types.TrainingJobStatusFailed:
|
case types.TrainingJobStatusFailed:
|
||||||
return fmt.Errorf("job %s finished with status %v\n", jobName, status.TrainingJobStatus)
|
return fmt.Errorf("job %s finished with status %v", jobName, status.TrainingJobStatus)
|
||||||
default:
|
default:
|
||||||
log.Printf("job %s finished with status %v\n", jobName, status.TrainingJobStatus)
|
l.Infof("job %s finished with status %v", jobName, status.TrainingJobStatus)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user