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

Commit 3368e6b

Browse files
author
Ludwig Schubert
committed
Fix Python 2 incompatibilty in ndimage_utils by importing division from future
1 parent 36f288c commit 3368e6b

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

lucid/misc/io/reading.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828
import os
2929
import re
3030
import logging
31-
from urllib.parse import urlparse, urljoin
31+
from urllib.parse import urlparse
3232
from future.moves.urllib import request
3333
from tensorflow import gfile
3434
from tempfile import gettempdir
35-
from io import BytesIO, StringIO
3635
import gc
3736
from filelock import FileLock
3837

39-
from lucid.misc.io.writing import write, write_handle
38+
from lucid.misc.io.writing import write_handle
4039

4140

4241
# create logger with module name, e.g. lucid.misc.io.reading
@@ -113,7 +112,7 @@ def read_handle(url, cache=None, mode="rb"):
113112
elif scheme in ("gs"):
114113
handle = _handle_gfile(url, mode=mode)
115114
else:
116-
handle = os.open(url, mode=mode)
115+
handle = open(url, mode=mode)
117116

118117
yield handle
119118
handle.close()

lucid/misc/ndimage_utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Copyright 2019 The Lucid Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
from __future__ import absolute_import, division, print_function
116
import numpy as np
217
from scipy import ndimage
318

lucid/misc/tfutil.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1+
# Copyright 2019 The Lucid Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ==============================================================================
15+
116
import tensorflow as tf
217

318

419
def create_session(target='', timeout_sec=10):
520
'''Create an intractive TensorFlow session.
6-
21+
722
Helper function that creates TF session that uses growing GPU memory
823
allocation and opration timeout. 'allow_growth' flag prevents TF
924
from allocating the whole GPU memory an once, which is useful
@@ -14,4 +29,3 @@ def create_session(target='', timeout_sec=10):
1429
config.gpu_options.allow_growth = True
1530
config.operation_timeout_in_ms = int(timeout_sec*1000)
1631
return tf.InteractiveSession(target=target, graph=graph, config=config)
17-

0 commit comments

Comments
 (0)