From 31ff2ddaf271b85886a05e4852065ea66450d34f Mon Sep 17 00:00:00 2001 From: Zhandong Jiao Date: Fri, 29 Mar 2024 10:42:22 -0400 Subject: [PATCH] Changed project directory paths, edited model types and optimizer/learning rates. --- cnnlstm_train.sh | 2 +- src/base/constants.py | 4 ++-- src/demo_model/test.py | 2 +- src/demo_model/train.py | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cnnlstm_train.sh b/cnnlstm_train.sh index 37d48e8..d9752b1 100644 --- a/cnnlstm_train.sh +++ b/cnnlstm_train.sh @@ -9,7 +9,7 @@ module load academic-ml/spring-2024 conda activate spring-2024-pyt # Change this path to point to your project directory -export PYTHONPATH="/projectnb/ds598/admin/tgardos/sp2024_midterm:$PYTHONPATH" # Set this!!! +export PYTHONPATH="/projectnb/ds598/students/jiaobill/sp2024_midterm:$PYTHONPATH" # Set this!!! python -m spacy download en_core_web_sm # download spacy model python src/cnn_lstm/train.py diff --git a/src/base/constants.py b/src/base/constants.py index a2c80c1..3319378 100644 --- a/src/base/constants.py +++ b/src/base/constants.py @@ -5,7 +5,7 @@ import spacy # set this path to where you want to save results -BASE_DIR = "/projectnb/ds598/projects/tgardos/sp2024_midterm/" +BASE_DIR = "/projectnb/ds598/students/jiaobill/sp2024_midterm/" # Do not edit. This points to the dataset folder DATA_BASE_DIR = "/projectnb/ds598/materials/datasets/vizwiz/captions/" @@ -53,5 +53,5 @@ DEMO_STD = np.array([58.395, 57.120, 57.375]) / 255 # SAVE PATHS -DEMO_SAVE_PATH = BASE_DIR + "RESULTS/git" +DEMO_SAVE_PATH = BASE_DIR + "RESULTS/git_new" CNNLSTM_SAVE_PATH = BASE_DIR + "RESULTS/cnn_lstm" diff --git a/src/demo_model/test.py b/src/demo_model/test.py index 31c8690..48ec0ac 100644 --- a/src/demo_model/test.py +++ b/src/demo_model/test.py @@ -33,7 +33,7 @@ # # Of course you should use the same model you trained with. try: - processor = AutoProcessor.from_pretrained("replace-with-model-choice", cache_dir=CACHE_DIR) + processor = AutoProcessor.from_pretrained("microsoft/git-base", cache_dir=CACHE_DIR) except Exception as e: print("You need to pick a pre-trained model from HuggingFace.") print("Exception: ", e) diff --git a/src/demo_model/train.py b/src/demo_model/train.py index 6372bdf..696d05f 100644 --- a/src/demo_model/train.py +++ b/src/demo_model/train.py @@ -32,7 +32,7 @@ # to encode and decode text and images. # https://huggingface.co/docs/transformers/model_doc/auto#transformers.AutoProcessor try: - processor = AutoProcessor.from_pretrained("replace-with-model-choice", cache_dir=CACHE_DIR) + processor = AutoProcessor.from_pretrained("microsoft/git-base", cache_dir=CACHE_DIR) except Exception as e: print("You need to pick a pre-trained model from HuggingFace.") print("Exception: ", e) @@ -72,15 +72,15 @@ # model you want to fine-tune. This will allow you to use the model to train and evaluate # on the VizWiz dataset. try: - model = AutoModelForCausalLM.from_pretrained("replace-with-model-choice", cache_dir=CACHE_DIR) + model = AutoModelForCausalLM.from_pretrained("microsoft/git-base", cache_dir=CACHE_DIR) except Exception as e: print("You need to pick a pre-trained model from HuggingFace.") print("Exception: ", e) + exit(1) ## TODO Select your model optimizer try: - raise NotImplementedError("Select your model optimizer") - optimizer = None # pick one from torch.optim + optimizer = torch.optim.AdamW(model.parameters(), lr=0.00001) except Exception as e: print("You need to pick an optimizer from torch.optim.") print("Exception: ", e) @@ -223,7 +223,7 @@ def get_val_examples(vizwizEval, vizwizRes, plot_captions_dict, epoch, method="C best_score = 0 -for epoch in range(3): +for epoch in range(10): print(f"Epoch: {epoch+1}") # Wrap the dataloader with tqdm for a progress bar progress_bar = tqdm( @@ -235,7 +235,7 @@ def get_val_examples(vizwizEval, vizwizRes, plot_captions_dict, epoch, method="C logger.info(f"Loss at epoch {epoch}: {loss}") # Evaluate the model every 3 epochs - if epoch % 3 == 0: + if epoch % 1 == 0: vizwizEval, vizwizRes, plot_captions_dict = evaluate( logger, epoch,