Skip to content

Commit

Permalink
remove frozen requirements (#105)
Browse files Browse the repository at this point in the history
* clean up requirements

* fix typechecking errors introduced by unfreezing requirements

* replace skimage op with cv2
  • Loading branch information
themattinthehatt authored Jul 28, 2023
1 parent 6135e5a commit a6ed589
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 56 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,15 @@ cd <SOME_FOLDER>
git clone https://github.com/danbider/lightning-pose.git
```

Then move into the newly-created repository folder, and install dependencies:
Then move into the newly-created repository folder:
```console
cd lightning-pose
pip install -e .
```
and install dependencies using one of the lines below that suits your needs best:
* `pip install -e . `: basic installation, covers most use-cases (note the period!)
* `pip install -e .[dev] `: basic install + dev tools
* `pip install -e .[extra_models] `: basic install + tools for loading resnet-50 simclr weights
* `pip install -e .[dev,extra_models] `: install all available requirements

This installation might take between 3-10 minutes, depending on your machine and internet connection.

Expand Down
13 changes: 11 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ If you have found a bug or would like to request a minor change, please

In order to contribute code to the repo, please follow the steps below.

You will also need to install the following dev packages:
Whenever you initially install the lightning pose repo, instead of
```bash
pip install flake8 isort
pip install -e .
```
run
```bash
pip install -e .[dev]
```

Alternatively, if you have already installed the repo, install the following dev packages:
```bash
pip install black flake8 isort
```

### Create a pull request
Expand Down
6 changes: 3 additions & 3 deletions lightning_pose/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"resnet50",
"resnet101",
"resnet152",
"resnet50_contrastive",
"resnet50_contrastive", # needs extra install: pip install -e .[extra_models]
"resnet50_animal_apose",
"resnet50_animal_ap10k",
"resnet50_human_jhmdb",
Expand All @@ -15,6 +15,6 @@
"efficientnet_b0",
"efficientnet_b1",
"efficientnet_b2",
"vit_h_sam",
"vit_b_sam",
# "vit_h_sam",
# "vit_b_sam",
]
11 changes: 9 additions & 2 deletions lightning_pose/models/backbones/torchvision.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import OrderedDict
from typing import Tuple

import torch
import torchvision.models as tvmodels
Expand Down Expand Up @@ -28,8 +29,14 @@ def build_backbone(

if backbone_arch == "resnet50_contrastive":
# load resnet50 pretrained using SimCLR on imagenet
from pl_bolts.models.self_supervised import SimCLR

try:
from pl_bolts.models.self_supervised import SimCLR
except ImportError:
raise Exception(
"lightning-bolts package is not installed.\n"
"Run `pip install lightning-bolts` "
"in order to access 'resnet50_contrastive' backbone"
)
ckpt_url = "https://pl-bolts-weights.s3.us-east-2.amazonaws.com/simclr/bolts_simclr_imagenet/simclr_imagenet.ckpt" # noqa: E501
simclr = SimCLR.load_from_checkpoint(ckpt_url, strict=False)
base = simclr.encoder
Expand Down
6 changes: 4 additions & 2 deletions lightning_pose/models/heatmap_tracker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Models that produce heatmaps of keypoints from images."""

from typing import Optional, Tuple, Union
from typing import Dict, Optional, Tuple, Union

import torch
from kornia.filters import filter2d
Expand All @@ -9,6 +9,7 @@
from omegaconf import DictConfig
from torch import nn
from torchtyping import TensorType
from typeguard import typechecked
from typing_extensions import Literal

from lightning_pose.data.utils import (
Expand Down Expand Up @@ -349,6 +350,7 @@ def predict_step(
return predicted_keypoints, confidence


@typechecked
class SemiSupervisedHeatmapTracker(SemiSupervisedTrackerMixin, HeatmapTracker):
"""Model produces heatmaps of keypoints from labeled/unlabeled images."""

Expand Down Expand Up @@ -411,7 +413,7 @@ def __init__(
# self.register_buffer("total_unsupervised_importance", torch.tensor(1.0))
self.total_unsupervised_importance = torch.tensor(1.0)

def get_loss_inputs_unlabeled(self, batch: UnlabeledBatchDict) -> dict:
def get_loss_inputs_unlabeled(self, batch: UnlabeledBatchDict) -> Dict:
"""Return predicted heatmaps and their softmaxes (estimated keypoints)."""
# images -> heatmaps
predicted_heatmaps = self.forward(batch["frames"])
Expand Down
4 changes: 2 additions & 2 deletions lightning_pose/models/heatmap_tracker_mhcrnn.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Models that produce heatmaps of keypoints from images."""

from typing import Optional, Tuple, Union
from typing import Dict, Optional, Tuple, Union

import torch
from kornia.geometry.subpix import spatial_softmax2d
Expand Down Expand Up @@ -259,7 +259,7 @@ def __init__(
# self.register_buffer("total_unsupervised_importance", torch.tensor(1.0))
self.total_unsupervised_importance = torch.tensor(1.0)

def get_loss_inputs_unlabeled(self, batch: UnlabeledBatchDict) -> dict:
def get_loss_inputs_unlabeled(self, batch: UnlabeledBatchDict) -> Dict:
"""Return predicted heatmaps and their softmaxes (estimated keypoints)."""
# images -> heatmaps
pred_heatmaps_crnn, pred_heatmaps_sf = self.forward(batch["frames"])
Expand Down
4 changes: 2 additions & 2 deletions lightning_pose/models/regression_tracker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Models that produce (x, y) coordinates of keypoints from images."""

from typing import Optional, Tuple, Union
from typing import Dict, Optional, Tuple, Union

import torch
from omegaconf import DictConfig
Expand Down Expand Up @@ -204,7 +204,7 @@ def __init__(
self.total_unsupervised_importance = torch.tensor(1.0)
# self.register_buffer("total_unsupervised_importance", torch.tensor(1.0))

def get_loss_inputs_unlabeled(self, batch: UnlabeledBatchDict) -> dict:
def get_loss_inputs_unlabeled(self, batch: UnlabeledBatchDict) -> Dict:
"""Return predicted heatmaps and their softmaxes (estimated keypoints)."""
predicted_keypoints = self.forward(batch["frames"])
# undo augmentation if needed
Expand Down
5 changes: 2 additions & 3 deletions lightning_pose/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def get_videos_in_dir(video_dir: str, return_mp4_only: bool = True) -> List[str]


@typechecked
def check_video_paths(video_paths: Union[List[str], str]) -> list:
def check_video_paths(video_paths: Union[List[str], str]) -> List[str]:
# get input data
if isinstance(video_paths, list):
# presumably a list of files
Expand All @@ -203,8 +203,7 @@ def check_video_paths(video_paths: Union[List[str], str]) -> list:
filenames = get_videos_in_dir(video_paths)
else:
raise ValueError(
"`video_paths_list` must be a list of files, a single file, "
+ "or a directory name"
"`video_paths_list` must be a list of files, a single file, or a directory name"
)
for filename in filenames:
assert filename.endswith(".mp4"), "video files must be mp4 format!"
Expand Down
21 changes: 11 additions & 10 deletions lightning_pose/utils/predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import time
from typing import List, Optional, Tuple, Union

import cv2
import lightning.pytorch as pl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import torch
from omegaconf import DictConfig, OmegaConf
from pytorch_lightning import LightningModule
from skimage.draw import disk
from torchtyping import TensorType
from tqdm import tqdm
from typeguard import typechecked
Expand Down Expand Up @@ -690,7 +690,7 @@ def create_labeled_video(
xs_arr,
ys_arr,
mask_array=None,
dotsize=5,
dotsize=4,
colormap="cool",
fps=None,
filename="movie.mp4",
Expand Down Expand Up @@ -719,14 +719,10 @@ def create_labeled_video(
colors = make_cmap(n_keypoints, cmap=colormap)

nx, ny = clip.size
duration = int(clip.duration - clip.start)
dur = int(clip.duration - clip.start)
fps_og = clip.fps

print(
"Duration of video [s]: {}, recorded with {} fps!".format(
np.round(duration, 2), np.round(fps_og, 2)
)
)
print(f"Duration of video [s]: {np.round(dur, 2)}, recorded at {np.round(fps_og, 2)} fps!")

# add marker to each frame t, where t is in sec
def add_marker(get_frame, t):
Expand All @@ -742,8 +738,13 @@ def add_marker(get_frame, t):
if mask_array[index, bpindex]:
xc = min(int(xs_arr[index, bpindex]), nx - 1)
yc = min(int(ys_arr[index, bpindex]), ny - 1)
rr, cc = disk(center=(yc, xc), radius=dotsize, shape=(ny, nx))
frame[rr, cc, :] = colors[bpindex]
frame = cv2.circle(
frame,
center=(xc, yc),
radius=dotsize,
color=colors[bpindex].tolist(),
thickness=-1
)
return frame

clip_marked = clip.fl(add_marker)
Expand Down
2 changes: 1 addition & 1 deletion lightning_pose/utils/scripts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Helper functions to build pipeline components from config dictionary."""

import os
from typing import Dict, Optional, Union
from typing import Dict, List, Optional, Union

import imgaug.augmenters as iaa
import lightning.pytorch as pl
Expand Down
65 changes: 38 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from setuptools import find_packages, setup

VERSION = "0.0.3"
VERSION = "0.0.4"

# add the README.md file to the long_description
with open("README.md", "r") as fh:
Expand Down Expand Up @@ -43,45 +43,56 @@ def get_cuda_version():
print(f"Found CUDA version: {cuda_version}, using DALI: {dali}")


# basic requirements
install_requires = [
"black==23.3.0",
"fiftyone==0.20.1",
"h5py==3.8.0",
"hydra-core==1.3.2",
"imgaug==0.4.0",
"kaleido==0.2.1",
"kornia==0.6.12",
"matplotlib==3.7.1",
"moviepy==1.0.3",
"opencv-python==4.7.0.72",
"pandas==2.0.1",
"pillow==9.5.0",
"pytest==7.3.1",
"fiftyone",
"h5py",
"hydra-core",
"imgaug",
"kaleido", # export plotly figures as static images
"kornia",
"lightning",
"matplotlib",
"moviepy",
"opencv-python",
"pandas>=2.0.0",
"pillow",
"plotly",
"pytest",
"scikit-learn",
"seaborn",
"streamlit",
"tensorboard",
"torchtyping",
"torchvision",
"typeguard",
"typing",
dali,
"tensorboard==2.13.0",
"lightning-bolts==0.6.0.post1",
"seaborn==0.12.2",
"scikit-image==0.20.0",
"scikit-learn==1.2.2",
"streamlit==1.22.0",
"torchtyping==0.1.4",
"torchvision==0.15.2",
"typeguard==3.0.2",
"typing==3.7.4.3",
"botocore==1.27.59",
]

# additional requirements
extras_require = {
"dev": {
"black",
"flake8",
"isort",
},
"extra_models": {
"lightning-bolts", # resnet-50 trained on imagenet using simclr
},
}


setup(
name="lightning-pose",
packages=find_packages(),
version=VERSION,
description="Semi-supervised pose estimation using Lightning.",
description="Semi-supervised pose estimation using pytorch lightning",
long_description=long_description,
long_description_content_type="text/markdown",
author="Dan Biderman and Matt Whiteway",
install_requires=install_requires, # load_requirements(PATH_ROOT),
install_requires=install_requires,
extras_require=extras_require,
author_email="[email protected]",
url="https://github.com/danbider/lightning-pose",
keywords=["machine learning", "deep learning", "computer_vision"],
Expand Down

0 comments on commit a6ed589

Please sign in to comment.