Upload folder using huggingface_hub
Browse files- requirements.txt +8 -8
- src/train.py +31 -6
requirements.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 1 |
+
--extra-index-url https://download.pytorch.org/whl/cpu
|
| 2 |
+
torch==2.9.1+cpu
|
| 3 |
+
torchvision==0.24.1+cpu
|
| 4 |
+
numpy>=1.24
|
| 5 |
+
pandas>=2.0
|
| 6 |
+
pyyaml>=6.0
|
| 7 |
+
pillow>=10.0
|
| 8 |
+
scikit-learn>=1.3
|
src/train.py
CHANGED
|
@@ -852,18 +852,43 @@ def fit_split_normalization(
|
|
| 852 |
groups = storm_ids_by_split(frame)
|
| 853 |
if not groups["train"]:
|
| 854 |
raise LeakageError("normalization stats may be fit on the train split only")
|
| 855 |
-
raw_images, _winds, _labels, _size = _load_examples(
|
| 856 |
-
config, frame, Path(manifest), "train", None, False
|
| 857 |
-
)
|
| 858 |
if uses_sequences(config):
|
|
|
|
|
|
|
|
|
|
| 859 |
norm_frames = [
|
| 860 |
raw_images[index, step]
|
| 861 |
for index in range(raw_images.shape[0])
|
| 862 |
for step in range(raw_images.shape[1])
|
| 863 |
]
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 867 |
|
| 868 |
|
| 869 |
def train(config: dict, manifest_path: str | Path | None = None) -> Path:
|
|
|
|
| 852 |
groups = storm_ids_by_split(frame)
|
| 853 |
if not groups["train"]:
|
| 854 |
raise LeakageError("normalization stats may be fit on the train split only")
|
|
|
|
|
|
|
|
|
|
| 855 |
if uses_sequences(config):
|
| 856 |
+
raw_images, _winds, _labels, _size = _load_examples(
|
| 857 |
+
config, frame, Path(manifest), "train", None, False
|
| 858 |
+
)
|
| 859 |
norm_frames = [
|
| 860 |
raw_images[index, step]
|
| 861 |
for index in range(raw_images.shape[0])
|
| 862 |
for step in range(raw_images.shape[1])
|
| 863 |
]
|
| 864 |
+
return fit_norm_stats(norm_frames, "train")
|
| 865 |
+
|
| 866 |
+
image_size = parse_image_size(config["data"]["image_size"])
|
| 867 |
+
max_missing = float(config["data"]["max_missing_fraction"])
|
| 868 |
+
rows = frame[frame["split"] == "train"]
|
| 869 |
+
if rows.empty:
|
| 870 |
+
raise LeakageError("normalization stats may be fit on the train split only")
|
| 871 |
+
manifest_path = Path(manifest)
|
| 872 |
+
count = 0
|
| 873 |
+
total = 0.0
|
| 874 |
+
total_sq = 0.0
|
| 875 |
+
for row in rows.itertuples(index=False):
|
| 876 |
+
path = resolve_image(manifest_path, row.image_path)
|
| 877 |
+
img = prepare_image(load_image(path), image_size, None, max_missing)
|
| 878 |
+
finite = img[np.isfinite(img)]
|
| 879 |
+
if finite.size > 0:
|
| 880 |
+
finite64 = finite.astype(np.float64, copy=False)
|
| 881 |
+
count += int(finite64.size)
|
| 882 |
+
total += float(finite64.sum())
|
| 883 |
+
total_sq += float((finite64 * finite64).sum())
|
| 884 |
+
if count == 0:
|
| 885 |
+
raise ValueError("train images have no finite pixels")
|
| 886 |
+
mean = float(total / count)
|
| 887 |
+
var = max(0.0, float((total_sq / count) - (mean ** 2)))
|
| 888 |
+
std = float(np.sqrt(var))
|
| 889 |
+
if std < 1e-6:
|
| 890 |
+
std = 1.0
|
| 891 |
+
return NormStats(mean=mean, std=std, source_split="train")
|
| 892 |
|
| 893 |
|
| 894 |
def train(config: dict, manifest_path: str | Path | None = None) -> Path:
|