-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathembedflag.py
More file actions
42 lines (36 loc) · 1.32 KB
/
Copy pathembedflag.py
File metadata and controls
42 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
import torch
import torch.nn as nn
import numpy as np
PASS_IMAGE_LOAD = True
# train, valid
mode = "valid"
if mode == "train":
PATH_TO_NUMPY_LOAD = "[PATH_TO_NUMPY_LOAD]"
FILENAME_PATH = "[FILENAME_PATH]"
SPLIT_PATH = "[SPLIT_PATH]"
elif mode == "valid":
PATH_TO_NUMPY_LOAD = "[PATH_TO_NUMPY_LOAD]"
FILENAME_PATH = "[FILENAME_PATH]"
SPLIT_PATH = "[SPLIT_PATH]"
FILENAME = []
with open(FILENAME_PATH, 'r') as file:
# Iterate over the file object, which yields lines one by one
for line in file:
# .strip() removes leading/trailing whitespace, including '\n'
cleaned_item = line.strip()
# Check to avoid adding blank lines if the original file had them
if cleaned_item:
FILENAME.append(cleaned_item)
def get_split_index(image):
image_idx = FILENAME.index(image)
with open(SPLIT_PATH, 'r') as file:
split = json.load(file)
for i, filename in enumerate(split):
if filename["start_index"] <= image_idx <= filename["end_index"]:
return i+1
raise ValueError(f"Image {image} not found in split index {image_idx}")
import torch
proj = np.load("./proj_1024_100.npy")
EMBED_DIM = 1024
__all__ = ["PASS_IMAGE_LOAD", "PATH_TO_NUMPY_LOAD", "FILENAME", "SPLIT_PATH", "get_split_index", "proj", "EMBED_DIM"]