Skip to content

Commit

Permalink
path changes
Browse files Browse the repository at this point in the history
  • Loading branch information
saleemhamo committed Jul 22, 2024
1 parent a4f51de commit 3030766
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 58 deletions.
64 changes: 32 additions & 32 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
name: Build and Push Docker Image

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: saleemhamo/ctfg_pipeline_fine_grained:v0.0

build-args: MOUNTED_CLAIM_DIRECTORY=/mnt/data
#name: Build and Push Docker Image
#
#on:
# push:
# branches:
# - main
#
#jobs:
# build:
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout repository
# uses: actions/checkout@v2
#
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1
#
# - name: Log in to Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
#
# - name: Build and push Docker image
# uses: docker/build-push-action@v2
# with:
# context: .
# push: true
# tags: saleemhamo/ctfg_pipeline_fine_grained:v0.0
#
# build-args: MOUNTED_CLAIM_DIRECTORY=/mnt/data
5 changes: 1 addition & 4 deletions models/coarse_grained/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ def main():

model = train_coarse_grained_model(train_loader, config)

docker_image_name = os.getenv('DOCKER_IMAGE_NAME', 'default_image')
job_id = os.getenv('JOB_ID', 'default_job')
docker_image_name = re.sub(r'[^a-zA-Z0-9]', '_', docker_image_name)
model_file_name = f"model_{docker_image_name}.pth"
model_file_name = "model"

save_path = save_model(model, COARSE_GRAINED_MODELS_DIR, custom_file_name=model_file_name)
logger.info(f"Model saved to {save_path}")
Expand Down
4 changes: 1 addition & 3 deletions models/fine_grained/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ def main():

model = fine_grained_retrieval(train_loader, config)

docker_image_name = os.getenv('DOCKER_IMAGE_NAME', 'default_image')
job_id = os.getenv('JOB_ID', 'default_job')
model_file_name = f"fine_grained_model_{docker_image_name}_{job_id}.pth"
model_file_name = f"model"

save_path = save_model(model, FINE_GRAINED_MODELS_DIR, custom_file_name=model_file_name)
logger.info(f"Model saved to {save_path}")
Expand Down
10 changes: 6 additions & 4 deletions utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os

# Base directory for the project
BASE_DIR = '/nfs/workspace/coarse-to-fine-dataset'

# Paths to external data directories
MOUNTED_CLAIM_DIRECTORY = os.getenv('MOUNTED_CLAIM_DIRECTORY', '/Users/saleemhamo/Desktop/MSc Project/project')
DATA_DIR = os.path.join(MOUNTED_CLAIM_DIRECTORY, 'datasets')
DATA_DIR = os.path.join(BASE_DIR, 'datasets')

# Logs directory
LOGS_DIR = os.path.join(MOUNTED_CLAIM_DIRECTORY, 'logs')
LOGS_DIR = os.path.join(BASE_DIR, 'logs')

# Charades STA
CHARADES_STA = "charades_sta"
Expand All @@ -16,6 +18,6 @@
CHARADES_ANNOTATIONS_TEST = os.path.join(CHARADES_ANNOTATIONS_DIR, 'charades_sta_test.txt')

# Save model directory
SAVE_MODEL_DIR = os.path.join(MOUNTED_CLAIM_DIRECTORY, 'saved_models')
SAVE_MODEL_DIR = os.path.join(BASE_DIR, 'saved_models')
COARSE_GRAINED_MODELS_DIR = os.path.join(SAVE_MODEL_DIR, 'coarse_grained')
FINE_GRAINED_MODELS_DIR = os.path.join(SAVE_MODEL_DIR, 'fine_grained')
11 changes: 3 additions & 8 deletions utils/logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os
import re
from datetime import datetime
from utils.constants import LOGS_DIR

# Ensure the logs directory exists
Expand Down Expand Up @@ -57,14 +57,9 @@ def error(self, message):
# Configure the logger
def setup_logger(name) -> SingletonLogger:
"""Function to setup a logger with the specified name and log file."""
docker_image_name = os.getenv('DOCKER_IMAGE_NAME', 'default_image')
job_id = os.getenv('JOB_ID', 'default_job')

# Replace invalid characters in the log file name
job_id = re.sub(r'[^a-zA-Z0-9]', '_', job_id)
docker_image_name = re.sub(r'[^a-zA-Z0-9]', '_', docker_image_name)

log_file_name = f"{docker_image_name}_{job_id}.log"
key = datetime.now().strftime("%Y%m%d_%H%M%S")
log_file_name = f"model_{key}.pth"
log_file_path = os.path.join(LOGS_DIR, log_file_name)
print(f"In setup_logger {name}: log_file_path={log_file_path}")
return SingletonLogger(name, log_file_path)
9 changes: 2 additions & 7 deletions utils/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@

def save_model(model, directory, model_name=None, key=None, custom_file_name=None):
max_file_name_length = 255 # Maximum file name length in Linux

if custom_file_name:
filename = custom_file_name
else:
if key is None:
key = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{model_name}_{key}.pth"
key = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{model_name}_{key}.pth"

# Ensure the directory exists
if not os.path.exists(directory):
Expand Down

0 comments on commit 3030766

Please sign in to comment.