This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import os | |
import h5py | |
import numpy as np | |
import rasterio as rio | |
hdf5_dir = "hdf5" | |
gtif_dir = "gtif" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pytorch_lightning import Trainer | |
from torchgeo.datamodules import InriaAerialImageLabelingDataModule | |
from torchgeo.trainers import SemanticSegmentationTask | |
datamodule = InriaAerialImageLabelingDataModule(root_dir="...", batch_size=64, num_workers=6) | |
task = SemanticSegmentationTask(model="resnet18", pretrained=True, learning_rate=0.1) | |
trainer = Trainer(gpus=1, default_root_dir="...") | |
trainer.fit(model=task, datamodule=datamodule) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from torch.utils.data import DataLoader | |
from torchgeo.datasets import VHR10 | |
dataset = VHR10(root="...", download=True, checksum=True) | |
dataloader = DataLoader(dataset, batch_size=128, shuffle=True, num_workers=4) | |
for batch in dataloader: | |
image = batch["image"] | |
label = batch["label"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
transform = AppendNDVI(index_red=0, index_nir=3) | |
sample = transform(sample) | |
sample["image"][-1] = (sample["image"][-1] + 1) / 2 | |
plt.imshow(sample["image"][-1], cmap="RdYlGn_r") | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from torchgeo.datasets import Sentinel2 | |
from torchgeo.transforms import AppendNDVI | |
dataset = Sentinel2(root="...") | |
sample = dataset[...] | |
fig = dataset.plot(sample) | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for batch in dataloader: | |
image = batch["image"] | |
mask = batch["mask"] | |
# train a model, or make predictions using a pre-trained model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sampler = RandomGeoSampler(dataset, size=256, length=10000) | |
dataloader = DataLoader(dataset, batch_size=128, sampler=sampler, collate_fn=stack_samples) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cdl = CDL(root="...", download=True, checksum=True) | |
dataset = landsat & cdl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from torch.utils.data import DataLoader | |
from torchgeo.datasets import CDL, Landsat7, Landsat8, stack_samples | |
from torchgeo.samplers import RandomGeoSampler | |
landsat7 = Landsat7(root="...") | |
landsat8 = Landsat8(root="...", bands=Landsat8.all_bands[1:-2]) | |
landsat = landsat7 | landsat8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Continuously kill processes | |
# Use Ctrl+C to exit | |
while true | |
do | |
read -p "kill " pid | |
if [[ "$pid" == $$ ]] |
NewerOlder