Skip to content

Commit

Permalink
logging -> logger (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppwwyyxx committed May 15, 2022
1 parent 78b4b3c commit 385dab5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion tensorboardX/caffe2_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .proto.graph_pb2 import GraphDef
from .proto.node_def_pb2 import NodeDef
from .proto.tensor_shape_pb2 import TensorShapeProto
logger = logging.getLogger(__name__)


def _make_unique_name(seen, name, min_version=0):
Expand Down Expand Up @@ -753,7 +754,7 @@ def _try_get_shapes(nets):
shapes, _ = workspace.InferShapesAndTypes(nets)
return shapes
except Exception as e:
logging.warning('Failed to compute shapes: %s', e)
logger.warning('Failed to compute shapes: %s', e)
return {}


Expand Down
5 changes: 3 additions & 2 deletions tensorboardX/comet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from PIL import Image
except ImportError:
comet_installed = False
logger = logging.getLogger(__name__)


class CometLogger:
Expand All @@ -34,14 +35,14 @@ def wrapper(*args, **kwargs):
if 'api_key' not in self._comet_config.keys():
comet_ml.init()
if comet_ml.get_global_experiment() is not None:
logging.warning("You have already created a comet \
logger.warning("You have already created a comet \
experiment manually, which might \
cause clashes")
self._experiment = comet_ml.Experiment(**self._comet_config)
self._logging = True
self._experiment.log_other("Created from", "tensorboardX")
except Exception as e:
logging.warning(e)
logger.warning(e)

if self._logging is True:
return method(*args, **kwargs)
Expand Down
3 changes: 2 additions & 1 deletion tensorboardX/pytorch_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .proto.tensor_shape_pb2 import TensorShapeProto
from .proto.versions_pb2 import VersionDef
from .proto_graph import node_proto
logger = logging.getLogger(__name__)

methods_OP = ['attributeNames', 'hasMultipleOutputs', 'hasUses', 'inputs',
'kind', 'outputs', 'outputsSize', 'scopeName']
Expand Down Expand Up @@ -246,7 +247,7 @@ def find_time_for(node_name):
memory=[AllocatorMemoryUsed(allocator_name="unknown",
total_bytes=int(np.prod(v.tensor_size)) * 4)]))
if should_show_warning:
logging.warning('time cost for node is the sum of CPU + GPU.')
logger.warning('time cost for node is the sum of CPU + GPU.')

return nodes, node_stats

Expand Down
7 changes: 4 additions & 3 deletions tensorboardX/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .proto import layout_pb2
from .x2num import make_np
from .utils import _prepare_video, convert_to_HWC, convert_to_NTCHW
logger = logging.getLogger(__name__)

_INVALID_TAG_CHARACTERS = _re.compile(r'[^-/\w\.]')

Expand All @@ -37,7 +38,7 @@ def _clean_tag(name):
new_name = _INVALID_TAG_CHARACTERS.sub('_', name)
new_name = new_name.lstrip('/') # Remove leading slashes
if new_name != name:
logging.info(
logger.info(
'Summary name %s is illegal; using %s instead.' % (name, new_name))
name = new_name
return name
Expand Down Expand Up @@ -377,7 +378,7 @@ def make_video(tensor, fps):
filename = tempfile.NamedTemporaryFile(suffix='.gif', delete=False).name

if moviepy.version.__version__.startswith("0."):
logging.warning('Upgrade to moviepy >= 1.0.0 to supress the progress bar.')
logger.warning('Upgrade to moviepy >= 1.0.0 to supress the progress bar.')
clip.write_gif(filename, verbose=False)
elif moviepy.version.__version__.startswith("1."):
# moviepy >= 1.0.0 use logger=None to suppress output.
Expand All @@ -392,7 +393,7 @@ def make_video(tensor, fps):
try:
os.remove(filename)
except OSError:
logging.warning('The temporary file used by moviepy cannot be deleted.')
logger.warning('The temporary file used by moviepy cannot be deleted.')

return Summary.Image(height=h, width=w, colorspace=c, encoded_image_string=tensor_string)

Expand Down
3 changes: 2 additions & 1 deletion tensorboardX/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
scalar, histogram, histogram_raw, image, audio, text,
pr_curve, pr_curve_raw, video, custom_scalars, image_boxes, mesh, hparams
)
logger = logging.getLogger(__name__)

numpy_compatible = numpy.ndarray
try:
Expand Down Expand Up @@ -789,7 +790,7 @@ def add_image_with_boxes(
if isinstance(labels, str):
labels = [labels]
if len(labels) != box_tensor.shape[0]:
logging.warning('Number of labels do not equal to number of box, skip the labels.')
logger.warning('Number of labels do not equal to number of box, skip the labels.')
labels = None
summary = image_boxes(
tag, img_tensor, box_tensor, dataformats=dataformats, labels=labels, **kwargs)
Expand Down
3 changes: 2 additions & 1 deletion tensorboardX/x2num.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import logging
import numpy as np
import six
logger = logging.getLogger(__name__)


def check_nan(array):
tmp = np.sum(array)
if np.isnan(tmp) or np.isinf(tmp):
logging.warning('NaN or Inf found in input tensor.')
logger.warning('NaN or Inf found in input tensor.')
return array


Expand Down

0 comments on commit 385dab5

Please sign in to comment.