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

Add support for description #66

Merged
merged 4 commits into from
Oct 20, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## neptune-tensorboard 1.1.0

### Changes
- Add support for `description` argument in `tf.summary.image()` ([#66](https://github.com/neptune-ai/neptune-tensorboard/pull/66))

## neptune-tensorboard 1.0.0

### Fixes
Expand Down
19 changes: 10 additions & 9 deletions src/neptune_tensorboard/integration/tensorflow_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ def track_scalar(name, data, step=None, description=None, run=None, base_namespa
run[base_namespace]["scalar"][name].append(data)


def track_image(name, data, step=None, run=None, base_namespace=None):
# expecting 2 or 3 dimensional tensor. If tensor is 4-dimentional,
# as in https://www.tensorflow.org/api_docs/python/tf/summary/image
# iterate over first dimension to send all images
shape = tf.shape(data)
if len(shape) >= 4:
for num in range(0, shape[0]):
run[base_namespace]["image"][name].append(File.as_image(data[num]))
def track_image(name, data, step=None, run=None, base_namespace=None, description=None):
# If number of images (tf.shape(data)[0]) > 1, append images as FileSeries, else upload as an image.
# ref: https://www.tensorflow.org/api_docs/python/tf/summary/image
k = tf.shape(data)[0]
if k > 1:
for num in range(k):
run[base_namespace]["image"][name].append(File.as_image(data[num]), description=description)
else:
run[base_namespace]["image"][name] = File.as_image(data)
if description:
warnings.warn(f"neptune-tensorboard: Uploading single image ({name}). Description will be ignored.")
run[base_namespace]["image"][name] = File.as_image(data[0])


def track_text(name, data, step=None, description=None, run=None, base_namespace=None):
Expand Down
12 changes: 10 additions & 2 deletions tests/test_tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ def test_logging():
tf.summary.scalar("scalar_tensor", data=tf.constant(0.1), step=1)

# Image
tf.summary.image("zeros", data=tf.zeros([3, 2, 2, 3]), step=1)
tf.summary.image(
"single_image", data=tf.random.uniform(shape=[1, 8, 8, 1]), step=1, description="singe_image_desc"
)

# Images
tf.summary.image(
"image_series", data=tf.random.uniform(shape=[3, 8, 8, 1]), step=1, description="image_series_desc"
)

# Text
tf.summary.text("some_text", data="Hello World!", step=1)
Expand All @@ -35,5 +42,6 @@ def fn(x):

assert run.exists("tensorboard")
assert run.exists("tensorboard/scalar/learning_rate")
assert run.exists("tensorboard/image/zeros")
assert run.exists("tensorboard/image/single_image")
assert run.exists("tensorboard/image/image_series")
assert run.exists("tensorboard/text/some_text")
Loading