Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cnnlstm_train.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/base/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion src/demo_model/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/demo_model/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down