Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Move common from_config code to ClassyHook (#453)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #453

Pull Request resolved: fairinternal/ClassyVision#79

As suggested in D20526787, moving common from_config code to parent class

Reviewed By: mannatsingh

Differential Revision: D20570762

fbshipit-source-id: 1fb51aa683deeddeae98b8bf71fb6a22e71362d9
  • Loading branch information
Aaron Adcock authored and facebook-github-bot committed Mar 23, 2020
1 parent 6e5fbea commit ffbad54
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 32 deletions.
4 changes: 0 additions & 4 deletions classy_vision/hooks/checkpoint_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ def __init__(
self.checkpoint_period: int = checkpoint_period
self.phase_counter: int = 0

@classmethod
def from_config(cls, config: Dict[str, Any]) -> "CheckpointHook":
return cls(**config)

def _save_checkpoint(self, task, filename):
if getattr(task, "test_only", False):
return
Expand Down
4 changes: 4 additions & 0 deletions classy_vision/hooks/classy_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def __init__(self, a, b):
def __init__(self):
self.state = ClassyHookState()

@classmethod
def from_config(cls, config) -> "ClassyHook":
return cls(**config)

def _noop(self, *args, **kwargs) -> None:
"""Derived classes can set their hook functions to this.
Expand Down
4 changes: 0 additions & 4 deletions classy_vision/hooks/exponential_moving_average_model_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ def __init__(
f"{decay} on device {device}"
)

@classmethod
def from_config(cls, config: Dict[str, Any]) -> "ExponentialMovingAverageModelHook":
return cls(**config)

def get_model_state_iterator(self, model: nn.Module) -> Iterable[Tuple[str, Any]]:
"""Get an iterator over the model state to apply EMA to."""
iterable = model.named_parameters()
Expand Down
4 changes: 0 additions & 4 deletions classy_vision/hooks/loss_lr_meter_logging_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ def __init__(self, log_freq: Optional[int] = None) -> None:
), "log_freq must be an int or None"
self.log_freq: Optional[int] = log_freq

@classmethod
def from_config(cls, config: Dict[str, Any]) -> "LossLrMeterLoggingHook":
return cls(**config)

def on_phase_end(self, task: "tasks.ClassyTask") -> None:
"""
Log the loss, optimizer LR, and meters for the phase.
Expand Down
4 changes: 0 additions & 4 deletions classy_vision/hooks/model_complexity_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class ModelComplexityHook(ClassyHook):
on_phase_end = ClassyHook._noop
on_end = ClassyHook._noop

@classmethod
def from_config(cls, config) -> "ModelComplexityHook":
return cls(**config)

def on_start(self, task: "tasks.ClassyTask") -> None:
"""Measure number of parameters, FLOPs and activations."""
self.num_flops = 0
Expand Down
4 changes: 0 additions & 4 deletions classy_vision/hooks/profiler_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class ProfilerHook(ClassyHook):
on_phase_end = ClassyHook._noop
on_end = ClassyHook._noop

@classmethod
def from_config(cls, config: Dict[str, Any]) -> "ProfilerHook":
return cls(**config)

def on_start(self, task: "tasks.ClassyTask") -> None:
"""Profile the forward pass."""
logging.info("Profiling forward pass...")
Expand Down
4 changes: 0 additions & 4 deletions classy_vision/hooks/progress_bar_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ def __init__(self) -> None:
self.bar_size: int = 0
self.batches: int = 0

@classmethod
def from_config(cls, config) -> "ProgressBarHook":
return cls(**config)

def on_phase_start(self, task: "tasks.ClassyTask") -> None:
"""Create and display a progress bar with 0 progress."""
if not progressbar_available:
Expand Down
4 changes: 0 additions & 4 deletions classy_vision/hooks/time_metrics_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ def __init__(self, log_freq: Optional[int] = None) -> None:
self.log_freq: Optional[int] = log_freq
self.start_time: Optional[float] = None

@classmethod
def from_config(cls, config: Dict[str, Any]) -> "TimeMetricsHook":
return cls(**config)

def on_phase_start(self, task: "tasks.ClassyTask") -> None:
"""
Initialize start time and reset perf stats
Expand Down
4 changes: 0 additions & 4 deletions classy_vision/hooks/visdom_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ def __init__(
self.metrics: Dict = {}
self.visdom: Visdom = Visdom(self.server, self.port)

@classmethod
def from_config(cls, config: Dict[str, Any]) -> "VisdomHook":
return cls(**config)

def on_phase_end(self, task: "tasks.ClassyTask") -> None:
"""
Plot the metrics on visdom.
Expand Down

0 comments on commit ffbad54

Please sign in to comment.