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

Commit ddd60ec

Browse files
committed
Resolve #306 Merge update to handle changes in Bokeh 3.0.
Changes thanks to @ZohebAbai in #301
1 parent a993686 commit ddd60ec

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

tensorflow_similarity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
__version__ = "0.16.9"
14+
__version__ = "0.16.10"
1515

1616

1717
from . import algebra # noqa

tensorflow_similarity/visualization/projector.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,25 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from __future__ import annotations
1415

1516
import base64
1617
import io
17-
from typing import Any, List, Mapping, Optional, Sequence
18+
from collections.abc import Mapping, Sequence
19+
from typing import Any
1820

1921
import numpy as np
2022
import PIL
2123
import umap
24+
from bokeh import __version__
2225
from bokeh.plotting import ColumnDataSource, figure, output_notebook, show
2326
from distinctipy import distinctipy
2427
from tqdm.auto import tqdm
2528

2629
from tensorflow_similarity.types import FloatTensor, Tensor
2730

2831

29-
def tensor2images(tensor: Tensor, size: Optional[int] = 64) -> List[str]:
32+
def tensor2images(tensor: Tensor, size: int = 64) -> list[str]:
3033
"""Convert tensor images back to in memory images
3134
encoded in base 64.
3235
@@ -69,11 +72,11 @@ def tensor2images(tensor: Tensor, size: Optional[int] = 64) -> List[str]:
6972

7073
def projector(
7174
embeddings: FloatTensor,
72-
labels: Optional[Sequence[Any]] = None,
73-
class_mapping: Optional[Sequence[int]] = None,
74-
images: Optional[Tensor] = None,
75+
labels: Sequence[Any] | None = None,
76+
class_mapping: Sequence[int] | None = None,
77+
images: Tensor | None = None,
7578
image_size: int = 64,
76-
tooltips_info: Optional[Mapping[str, Sequence[str]]] = None,
79+
tooltips_info: Mapping[str, Sequence[str]] | None = None,
7780
pt_size: int = 3,
7881
colorize: bool = True,
7982
pastel_factor: float = 0.1,
@@ -183,13 +186,23 @@ def projector(
183186
# to bokeh format
184187
source = ColumnDataSource(data=data)
185188
output_notebook()
186-
fig = figure(
187-
tooltips=tooltips,
188-
plot_width=plot_size,
189-
plot_height=plot_size,
190-
active_drag=active_drag,
191-
active_scroll="wheel_zoom",
192-
)
189+
# Bokeh backward compatibility
190+
if int(__version__.split(".")[0]) >= 3:
191+
fig = figure(
192+
tooltips=tooltips,
193+
width=plot_size,
194+
height=plot_size,
195+
active_drag=active_drag,
196+
active_scroll="wheel_zoom",
197+
)
198+
else:
199+
fig = figure(
200+
tooltips=tooltips,
201+
plot_width=plot_size,
202+
plot_height=plot_size,
203+
active_drag=active_drag,
204+
active_scroll="wheel_zoom",
205+
)
193206

194207
# remove grid and axis
195208
fig.xaxis.visible = False

0 commit comments

Comments
 (0)