Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply pyupgrade to update code style #662

Merged
merged 2 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions deepcell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Package for single cell image segmentation with convolutional neural networks"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from deepcell._version import __version__

Expand All @@ -53,7 +50,3 @@
from deepcell.training import train_model_sample
from deepcell.training import train_model_siamese_daughter
from deepcell.utils import *

del absolute_import
del division
del print_function
2 changes: 1 addition & 1 deletion deepcell/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
__description__ = 'Deep learning for single cell image segmentation'
__url__ = 'https://github.com/vanvalenlab/deepcell-tf'
__version__ = '0.12.5'
__download_url__ = '{}/tarball/{}'.format(__url__, __version__)
__download_url__ = f'{__url__}/tarball/{__version__}'
__author__ = 'The Van Valen Lab'
__author_email__ = 'vanvalen@caltech.edu'
__license__ = 'LICENSE'
Expand Down
7 changes: 0 additions & 7 deletions deepcell/applications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Deepcell Applications - Pre-trained models for specific functions"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from deepcell.applications.application import Application
from deepcell.applications.cytoplasm_segmentation import CytoplasmSegmentation
Expand All @@ -37,7 +34,3 @@
from deepcell.applications.cell_tracking import CellTracking
from deepcell.applications.label_detection import LabelDetection
from deepcell.applications.scale_detection import ScaleDetection

del absolute_import
del division
del print_function
5 changes: 1 addition & 4 deletions deepcell/applications/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Base class for applications"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import logging
import timeit
Expand All @@ -37,7 +34,7 @@
from deepcell_toolbox.utils import resize, tile_image, untile_image


class Application(object):
class Application:
"""Application object that takes a model with weights
and manages predictions

Expand Down
3 changes: 0 additions & 3 deletions deepcell/applications/application_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Tests for Application"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from itertools import product
from unittest.mock import Mock
Expand Down
5 changes: 1 addition & 4 deletions deepcell/applications/cell_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""A model that can detect whether 2 cells are same, different, or related."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os

Expand Down Expand Up @@ -140,7 +137,7 @@ def __init__(self,
model_path = os.path.splitext(archive_path)[0]
model = tf.keras.models.load_model(model_path)

super(CellTracking, self).__init__(
super().__init__(
model,
model_mpp=MODEL_MPP,
preprocessing_fn=None,
Expand Down
3 changes: 0 additions & 3 deletions deepcell/applications/cell_tracking_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Tests for CellTracking Application"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorflow.python.platform import test
import numpy as np
Expand Down
5 changes: 1 addition & 4 deletions deepcell/applications/cytoplasm_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Cytoplasmic segmentation application"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os

Expand Down Expand Up @@ -106,7 +103,7 @@ def __init__(self, model=None,
model_path = os.path.splitext(archive_path)[0]
model = tf.keras.models.load_model(model_path)

super(CytoplasmSegmentation, self).__init__(
super().__init__(
model,
model_image_shape=model.input_shape[1:],
model_mpp=0.65,
Expand Down
3 changes: 0 additions & 3 deletions deepcell/applications/cytoplasm_segmentation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Tests for CytoplasmSegmentationModel"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorflow.python.platform import test
import numpy as np
Expand Down
5 changes: 1 addition & 4 deletions deepcell/applications/label_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Classify the type of an input image to send the data to the correct model"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os

Expand Down Expand Up @@ -139,7 +136,7 @@ def __init__(self, model=None):
model_path = os.path.splitext(archive_path)[0]
model = tf.keras.models.load_model(model_path)

super(LabelDetection, self).__init__(
super().__init__(
model,
model_image_shape=model.input_shape[1:],
model_mpp=0.65,
Expand Down
3 changes: 0 additions & 3 deletions deepcell/applications/label_detection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Tests for LabelDetectionModel"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import numpy as np
import tensorflow as tf
Expand Down
7 changes: 2 additions & 5 deletions deepcell/applications/mesmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Mesmer application"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os

Expand Down Expand Up @@ -58,7 +55,7 @@ def mesmer_preprocess(image, **kwargs):
"""

if len(image.shape) != 4:
raise ValueError("Image data must be 4D, got image of shape {}".format(image.shape))
raise ValueError(f"Image data must be 4D, got image of shape {image.shape}")

output = np.copy(image)
threshold = kwargs.get('threshold', True)
Expand Down Expand Up @@ -221,7 +218,7 @@ def __init__(self, model=None):
model_path = os.path.splitext(archive_path)[0]
model = tf.keras.models.load_model(model_path)

super(Mesmer, self).__init__(
super().__init__(
model,
model_image_shape=model.input_shape[1:],
model_mpp=0.5,
Expand Down
3 changes: 0 additions & 3 deletions deepcell/applications/mesmer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Tests for Mesmer Application"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import pytest

Expand Down
3 changes: 0 additions & 3 deletions deepcell/applications/multiplex_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,5 @@
Deprecated in favor of ``deepcell.applications.Mesmer`` instead.
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from deepcell.applications.mesmer import Mesmer as MultiplexSegmentation
5 changes: 1 addition & 4 deletions deepcell/applications/nuclear_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Nuclear segmentation application"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os

Expand Down Expand Up @@ -119,7 +116,7 @@ def __init__(self, model=None,
model_path = os.path.splitext(archive_path)[0]
model = tf.keras.models.load_model(model_path)

super(NuclearSegmentation, self).__init__(
super().__init__(
model,
model_image_shape=model.input_shape[1:],
model_mpp=MODEL_MPP,
Expand Down
3 changes: 0 additions & 3 deletions deepcell/applications/nuclear_segmentation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Tests for NuclearSegmentationApplication"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorflow.python.platform import test
import numpy as np
Expand Down
5 changes: 1 addition & 4 deletions deepcell/applications/scale_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Detect the scale of input data for rescaling for other models"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os

Expand Down Expand Up @@ -137,7 +134,7 @@ def __init__(self, model=None):
model_path = os.path.splitext(archive_path)[0]
model = tf.keras.models.load_model(model_path)

super(ScaleDetection, self).__init__(
super().__init__(
model,
model_image_shape=model.input_shape[1:],
model_mpp=0.65,
Expand Down
3 changes: 0 additions & 3 deletions deepcell/applications/scale_detection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Tests for ScaleDetectionModel"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import numpy as np
import tensorflow as tf
Expand Down
9 changes: 3 additions & 6 deletions deepcell/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Custom Callbacks for DeepCell"""

from __future__ import absolute_import
from __future__ import print_function
from __future__ import division

import timeit

Expand All @@ -40,7 +37,7 @@ class InferenceTimer(tf.keras.callbacks.Callback):
"""Callback to log inference speed per epoch."""

def __init__(self, samples=100):
super(InferenceTimer, self).__init__()
super().__init__()
self._samples = int(samples)
self._batch_times = []
self._samples_seen = []
Expand Down Expand Up @@ -70,8 +67,8 @@ def on_predict_end(self, logs=None):
avg = np.mean(per_sample)
std = np.std(per_sample)

print('Average inference speed per sample for %s total samples: '
'%0.5fs ± %0.5fs.' % (total_samples, avg, std))
print('Average inference speed per sample for {} total samples: '
'{:0.5f}s ± {:0.5f}s.'.format(total_samples, avg, std))

def on_epoch_end(self, epoch, logs=None):
shape = tuple([self._samples] + list(self.model.input_shape[1:]))
Expand Down
3 changes: 0 additions & 3 deletions deepcell/callbacks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Custom Callbacks for DeepCell"""

from __future__ import absolute_import
from __future__ import print_function
from __future__ import division

import sys

Expand Down
8 changes: 0 additions & 8 deletions deepcell/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Data utilities using ``tf.data``."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


def split_dataset(dataset, val_size, test_size=0):
Expand Down Expand Up @@ -77,8 +74,3 @@ def split_dataset(dataset, val_size, test_size=0):


from deepcell.data import tracking


del absolute_import
del division
del print_function
11 changes: 4 additions & 7 deletions deepcell/data/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Dataset Builders"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import math
import functools
Expand All @@ -50,7 +47,7 @@
from deepcell.data import split_dataset


class Track(object): # pylint: disable=useless-object-inheritance
class Track: # pylint: disable=useless-object-inheritance

def __init__(self, path=None, tracked_data=None,
appearance_dim=32, distance_threshold=64,
Expand Down Expand Up @@ -289,9 +286,9 @@ def concat_adj_matrices(tracks, matrix_name):

# TODO: these keys must match the Track attributes.
data_dict = {
'appearances': get_array_of_max_shape((t.appearances for t in tracks)),
'centroids': get_array_of_max_shape((t.centroids for t in tracks)),
'morphologies': get_array_of_max_shape((t.morphologies for t in tracks)),
'appearances': get_array_of_max_shape(t.appearances for t in tracks),
'centroids': get_array_of_max_shape(t.centroids for t in tracks),
'morphologies': get_array_of_max_shape(t.morphologies for t in tracks),
}

for track in tracks:
Expand Down
5 changes: 1 addition & 4 deletions deepcell/data/tracking_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
# ==============================================================================
"""Tests for tracking functions"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from absl.testing import parameterized

Expand Down Expand Up @@ -75,7 +72,7 @@ def get_dummy_data(num_labels=3, batches=2):
return data


class TestTrack(object):
class TestTrack:

def test_init(self, mocker):
num_labels = 3
Expand Down
Loading