forked from tensorflow/lucid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial infrastructure setup and Python 2&3 fixes.
- Loading branch information
Ludwig Schubert
committed
Jan 31, 2018
1 parent
f6b802b
commit a6e81c3
Showing
21 changed files
with
297 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
end_of_line = lf | ||
charset = utf-8 | ||
|
||
# Docstrings and comments use max_line_length = 79 | ||
[*.py] | ||
max_line_length = 79 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
**.pyc | ||
dist | ||
.eggs | ||
.cache | ||
.tox | ||
.pytest_cache | ||
*.egg-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# file GENERATED by distutils, do NOT edit | ||
setup.cfg | ||
setup.py | ||
lucid/__init__.py | ||
lucid/optvis/__init__.py | ||
lucid/optvis/objectives.py | ||
lucid/optvis/param.py | ||
lucid/optvis/render.py | ||
lucid/optvis/resize_bilinear_nd.py | ||
lucid/optvis/transform.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include tox.ini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +0,0 @@ | ||
# Copyright 2018 The Deepviz Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
import show | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"""UnifiedIO provides wrappers around IO functions. | ||
This is meant to make transparent which data store we are working with. | ||
""" | ||
|
||
from __future__ import absolute_import, division, print_function | ||
from future.standard_library import install_aliases | ||
install_aliases() | ||
|
||
import os | ||
import re | ||
from urllib.parse import urlparse, urljoin | ||
from future.moves.urllib.request import urlopen | ||
from tensorflow import gfile | ||
from tempfile import gettempdir | ||
|
||
|
||
def read(url): | ||
"""Read from any URL. | ||
Internally differentiates between URLs supported by tf.gfile, such as URLs | ||
with the Google Cloud Storage scheme ('gs://...') or local paths, and HTTP | ||
URLs. This way users don't need to know about the underlying fetch mechanism. | ||
Args: | ||
url: a URL including scheme or a local path | ||
Returns: | ||
All bytes form the specified resource if it could be reached. | ||
""" | ||
scheme = urlparse(url).scheme | ||
if scheme in ('http', 'https'): | ||
return read_web_url(url) | ||
elif scheme == 'gs': | ||
return read_gcs_url(url) | ||
else: | ||
return read_path(url) | ||
|
||
|
||
RESERVED_PATH_CHARS = re.compile("[^a-zA-Z0-9]") | ||
def read_and_cache(url): | ||
local_name = RESERVED_PATH_CHARS.sub('_', url) | ||
local_path = os.path.join(gettempdir(), local_name) | ||
if os.path.exists(local_path): | ||
print("Trying cached file '{}'.".format(local_path)) | ||
return read_path(local_path) | ||
else: | ||
print("Caching URL '{}' locally at '{}'.".format(url, local_path)) | ||
result = read(url) | ||
save(result, local_path) | ||
return result | ||
|
||
|
||
def read_web_url(url): | ||
print('read_web_url', url) | ||
return urlopen(url).read() | ||
|
||
|
||
def read_gcs_url(url): | ||
# TODO: transparantly allow authenticated access through storage API | ||
_, resource_name = url.split('://') | ||
base_url = 'https://storage.googleapis.com/' | ||
url = urljoin(base_url, resource_name) | ||
return read_web_url(url) | ||
|
||
|
||
def read_path(path): | ||
with gfile.Open(path, 'rb') as handle: | ||
result = handle.read() | ||
return result | ||
|
||
|
||
def save(bytes, url): | ||
assert not is_web_url(url) | ||
save_to_path(bytes, url) | ||
|
||
|
||
def save_to_path(bytes, path): | ||
with gfile.Open(path, 'wb') as handle: | ||
handle.write(bytes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +0,0 @@ | ||
# Copyright 2018 The Deepviz Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
|
||
|
||
from vision_models import * | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +0,0 @@ | ||
# Copyright 2018 The Deepviz Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
|
||
import objectives | ||
import param | ||
import transform | ||
import render | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.