Skip to content

Commit

Permalink
Merge pull request #149 from phborba/dev
Browse files Browse the repository at this point in the history
Version 0.17.0
  • Loading branch information
phborba committed Aug 15, 2022
2 parents 650b304 + 96d39b4 commit 6cbbf3b
Show file tree
Hide file tree
Showing 73 changed files with 1,903 additions and 520 deletions.
1 change: 1 addition & 0 deletions .github/workflows/python-app.yml
Expand Up @@ -46,6 +46,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install flake8 pytest parameterized coverage
pip install torch==1.10.0
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.10.0+cpu.html
if [ -f requirements.txt ]; then pip install --upgrade --upgrade-strategy eager -r requirements.txt; fi
pip install .
Expand Down
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
@@ -1,11 +1,12 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 19.3b0
rev: 22.6.0
hooks:
- id: black
exclude: ^dist/
6 changes: 4 additions & 2 deletions .vscode/launch.json
Expand Up @@ -23,7 +23,8 @@
"env" : {
"CONFIG_PATH": "../../mestrado_experimentos_dissertacao/pytorch/",
"CONFIG_NAME": "predict_polygons_hrnet_ocr_w48_frame_field_local"
}
},
"justMyCode": false,
},
{
"name": "Python: Remote Attach",
Expand All @@ -45,7 +46,8 @@
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
"console": "integratedTerminal",
"justMyCode": false,
}
]
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Expand Up @@ -24,4 +24,5 @@
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"python.analysis.extraPaths": [],
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,10 @@
# Version 0.17.0

- New evaluation metrics;
- New evaluation on test set;
- New inference service with image upload;
- Bug fixes;

# Version 0.16.4


Expand Down
Expand Up @@ -51,7 +51,9 @@ class DataLoaderConfig:

@dataclass
class DatasetConfig:
_target_: str = "pytorch_segmentation_models_trainer.dataset_loader.dataset.SegmentationDataset"
_target_: str = (
"pytorch_segmentation_models_trainer.dataset_loader.dataset.SegmentationDataset"
)
input_csv_path: str = MISSING
root_dir: str = MISSING
gpu_augmentation_list: List = field(default_factory=list)
Expand Down
Expand Up @@ -38,7 +38,9 @@ class SegParamsConfig:

@dataclass
class SegLossConfig:
_target_: str = "pytorch_segmentation_models_trainer.custom_losses.base_loss.SegLoss"
_target_: str = (
"pytorch_segmentation_models_trainer.custom_losses.base_loss.SegLoss"
)
name: str = "seg"
gt_channel_selector: SegParamsConfig = field(default_factory=SegParamsConfig)
bce_coef: float = 0.5
Expand Down
Expand Up @@ -54,7 +54,9 @@ class PLTrainerConfig:
max_epochs: str = "${hyperparameters.epochs}"
gpus: int = -1
precision: int = 32
default_root_dir: str = "/experiment_data/${backbone.name}_${hyperparameters.model_name}"
default_root_dir: str = (
"/experiment_data/${backbone.name}_${hyperparameters.model_name}"
)


@dataclass
Expand Down
Expand Up @@ -49,7 +49,7 @@
from pytorch_segmentation_models_trainer.utils import polygonrnn_utils


class ImageSegmentationResultCallback(pl.callbacks.base.Callback):
class ImageSegmentationResultCallback(pl.callbacks.Callback):
def __init__(
self,
n_samples: int = None,
Expand Down Expand Up @@ -151,48 +151,47 @@ def on_validation_end(self, trainer, pl_module):
val_ds = pl_module.val_dataloader()
device = pl_module.device
logger = trainer.logger
batch = next(iter(val_ds))
image_display = batch_denormalize_tensor(batch["image"]).to("cpu")
pred = pl_module(batch["image"].to(device))
self.n_samples = (
n_samples = (
pl_module.val_dataloader().batch_size
if self.n_samples is None
else self.n_samples
)
for i in range(self.n_samples):
image = image_display[i].numpy()
mask = batch["gt_polygons_image"][i]
predicted_mask = pred["seg"][i]
predicted_mask = predicted_mask.to("cpu")
plot_title = val_ds.dataset.get_path(i)
crossfield = pred["crossfield"]
np_crossfield = crossfield.cpu().detach().numpy().transpose(0, 2, 3, 1)
image_to_plot = np.transpose(image, (1, 2, 0))
# image_plot_crossfield_list = [
# get_image_plot_crossfield(
# _crossfield, crossfield_stride=10, width=0.2
# )
# for _crossfield in np_crossfield
# ]
axarr, fig = generate_visualization(
fig_title=plot_title,
image=image_to_plot,
ground_truth_mask=self.prepare_mask_to_plot(mask.numpy()[0]),
predicted_mask=self.prepare_mask_to_plot(predicted_mask.numpy()[0]),
ground_truth_boundary=self.prepare_mask_to_plot(mask.numpy()[1]),
predicted_boundary=self.prepare_mask_to_plot(predicted_mask.numpy()[1]),
# crossfield=image_plot_crossfield_list[i],
)
fig.tight_layout()
fig.subplots_adjust(top=0.95)
if self.save_outputs:
saved_image = self.save_plot_to_disk(
plt, plot_title, trainer.current_epoch
)
self.log_data_to_tensorboard(
saved_image, plot_title, logger, trainer.current_epoch
current_item = 0
for batch in val_ds:
if current_item >= n_samples:
break
images = batch["image"]
image_display = batch_denormalize_tensor(images).to("cpu")
pred = pl_module(images.to(device))
for i in range(images.shape[0]):
if current_item >= n_samples:
break
mask = batch["gt_polygons_image"][i]
predicted_mask = pred["seg"][i]
predicted_mask = predicted_mask.to("cpu")
plot_title = batch["path"][i]
image_to_plot = np.transpose(image_display[i], (1, 2, 0))
axarr, fig = generate_visualization(
fig_title=plot_title,
image=image_to_plot,
ground_truth_mask=self.prepare_mask_to_plot(mask.numpy()[0]),
predicted_mask=self.prepare_mask_to_plot(predicted_mask.numpy()[0]),
ground_truth_boundary=self.prepare_mask_to_plot(mask.numpy()[1]),
predicted_boundary=self.prepare_mask_to_plot(
predicted_mask.numpy()[1]
),
)
plt.close(fig)
fig.tight_layout()
fig.subplots_adjust(top=0.95)
if self.save_outputs:
saved_image = self.save_plot_to_disk(
plt, plot_title, trainer.current_epoch
)
self.log_data_to_tensorboard(
saved_image, plot_title, logger, trainer.current_epoch
)
plt.close(fig)
current_item += 1
return


Expand Down Expand Up @@ -345,13 +344,15 @@ def on_validation_end(self, trainer, pl_module):
pl_module.val_seq_len,
)
gt_polygon_list = prepared_item["shapely_polygon_list"]
predicted_polygon_list = polygonrnn_utils.get_vertex_list_from_batch_tensors(
output_batch_polygons,
prepared_item["scale_h"],
prepared_item["scale_w"],
prepared_item["min_col"],
prepared_item["min_row"],
grid_size=val_ds.dataset.grid_size,
predicted_polygon_list = (
polygonrnn_utils.get_vertex_list_from_batch_tensors(
output_batch_polygons,
prepared_item["scale_h"],
prepared_item["scale_w"],
prepared_item["min_col"],
prepared_item["min_row"],
grid_size=val_ds.dataset.grid_size,
)
)
saved_image = self.build_polygon_vis(
image_path,
Expand Down

0 comments on commit 6cbbf3b

Please sign in to comment.