Train Model

Purpose

Ridescan requires a model to be calibrated based on the normal routine of your robot and mission by uploading 15 routine data files.

Note: If you're not using our package, you'll need to implement the file upload via api yourself. And pass down the list of 'unique_filename's to 'training_data' parameter you will get after the upload of 15 files individually.

Request Parameters

  • robot_name (string, required)
  • mission_name (string, required)
  • training_files (list of strings, required)
  • robot_type - 0 for Spot, 1 for UR6 (integer, required)
  • retrain (boolean, required)

Headers

  • Authorization: Bearer <jwt>
  • Content-Type: application/json
API_KEY = os.environ.get("API_KEY")

def train_model():
    training_data_path = "./test_data/sample_csv/train_data/"  # Change this to your actual directory

    # Define robot and mission names
    # Robot types
    # 0 - Spot
    # 1 - UR6

    robot_name = "Spot"
    mission_name = "Carrying item to location"
    robot_type = 0

    # Initialize calculator with Flask API configuration using direct access token
    calculator = RiskScoreCalculator(api_key=API_KEY)

    # select training and inference files
    # Choose the correct file type as needed, supported types are .bag, .csv and .zip
    # Spot - (.bag, .zip)  
    # UR6 - (.csv)

    training_files = glob.glob(os.path.join(training_data_path, "*.csv"))[:15]  # Limit to first 15 files for training, adjust as needed

    try:
        success, response = calculator.train_model(
            robot_name=robot_name,
            mission_name=mission_name,
            training_files=training_files,
            robot_type=robot_type,
            retrain=False, 
        )
        
        if success:
            print("Model training initiated successfully")
            print(f"Training response: {response}")
            
        else:
            print(f"Model training failed: {response}")
            return

    except Exception as e:
        print(f"Model training failed with exception: {e}")
        return
    

Sample Response

{
  "success": true,
  "message": "Training started successfully",
  "details": {
    "robot_name": "Spot",
    "mission_name": "Carrying item to location"
  }
}

Want to test with real data?

Download a sample ZIP file with example data to get started right away.

Download Sample ZIP