TFTrainWithLoadAndSave generates PAI-TF train program. Load pre-trained model if modelPathToLoad != "". Save the trained model to modelPathToSave.
(ir *ir.TrainStmt, session *pb.Session, modelPathToSave, modelPathToLoad string, cc *ClusterConfig)
| 50 | // Load pre-trained model if modelPathToLoad != "". |
| 51 | // Save the trained model to modelPathToSave. |
| 52 | func TFTrainWithLoadAndSave(ir *ir.TrainStmt, session *pb.Session, modelPathToSave, modelPathToLoad string, cc *ClusterConfig) (string, error) { |
| 53 | // Distributed training must call train_and_evaluate, which need the user to specify validation.select |
| 54 | valSelect, valOK := ir.Attributes["validation.select"] |
| 55 | hasVal := true |
| 56 | if !valOK || valSelect.(string) == "" { |
| 57 | hasVal = false |
| 58 | } |
| 59 | if cc.Worker.Count > 1 && !hasVal { |
| 60 | return "", fmt.Errorf("Distributed training must specify WITH validation.select") |
| 61 | } |
| 62 | |
| 63 | loadCode, err := generateLoadOSSModelCode(ir.Estimator, modelPathToLoad) |
| 64 | if err != nil { |
| 65 | return "", err |
| 66 | } |
| 67 | |
| 68 | trainCode, err := tensorflow.Train(ir, session) |
| 69 | if err != nil { |
| 70 | return "", err |
| 71 | } |
| 72 | |
| 73 | fullCode := fmt.Sprintf("%s\n%s", loadCode, trainCode) |
| 74 | return fullCode, nil |
| 75 | } |
| 76 | |
| 77 | // TFLoadAndPredict generates PAI-TF prediction program. |
| 78 | func TFLoadAndPredict(ir *ir.PredictStmt, session *pb.Session, modelPath string) (string, error) { |
no test coverage detected