Understanding the Integration Requirements
- Identify the objectives of integrating Keras with Jira. Typically, this involves reporting model training status or results to Jira for project management and documentation purposes.
- Ensure you have a running Jira instance and access to its API for creating and updating issues.
- Verify that you have a Python environment set up and Keras installed, along with necessary libraries like `requests` for making API calls.
Setup Jira API Access
- Generate an API token in Jira to authenticate API requests. Go to your account settings, then security, and create a new API token.
- Note down your Jira domain and project key. These will be used in API endpoints to interact with specific issues.
Prepare Your Environment
- Ensure Python is installed, preferably Python 3.6 or higher for compatibility with Keras.
- Install necessary libraries by running:
pip install keras requests
Set Up Keras Callback for Integration
- Create a custom Keras callback to send updates to Jira. This callback will trigger at defined points during the training process.
import requests
from keras.callbacks import Callback
class JiraCallback(Callback):
def __init__(self, jira_url, api_token, project_key, issue_summary):
super(JiraCallback, self).__init__()
self.jira_url = jira_url
self.headers = {
'Authorization': f'Basic {api_token}',
'Content-Type': 'application/json'
}
self.project_key = project_key
self.issue_summary = issue_summary
def on_epoch_end(self, epoch, logs=None):
issue_data = {
"fields": {
"project": {
"key": self.project_key
},
"summary": f"{self.issue_summary} - Epoch {epoch + 1}",
"description": f"Completed epoch {epoch + 1} with accuracy {logs['accuracy']:.4f} and loss {logs['loss']:.4f}.",
"issuetype": {
"name": "Task"
}
}
}
response = requests.post(f"{self.jira_url}/rest/api/2/issue", headers=self.headers, json=issue_data)
if response.status_code == 201:
print(f"Created Jira issue for epoch {epoch + 1}")
else:
print(f"Failed to create Jira issue: {response.content}")
Integrate the Callback into Your Model Training
- Instantiate the `JiraCallback` with your Jira credentials and add it to the list of callbacks when fitting your model.
jira_callback = JiraCallback(
jira_url='https://your-jira-domain.atlassian.net',
api_token='your_encoded_api_token',
project_key='PROJECT_KEY',
issue_summary='Model Training Update'
)
model.fit(x_train, y_train, epochs=10, callbacks=[jira_callback])
Test Your Integration
- Run your model training and observe the console output for successful Jira issue creation messages.
- Log in to Jira and verify that issues are created and updated as expected with the training progress.
Troubleshoot Common Issues
- If issues are not created, check the API token and authorization headers for correctness.
- Ensure your Jira URL and endpoints are correct, especially if using a self-hosted Jira server.