Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
Replace identity
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberZHG committed Jul 8, 2020
1 parent b350653 commit b1ab67e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 41 deletions.
22 changes: 9 additions & 13 deletions .travis.yml
@@ -1,18 +1,14 @@
dist: xenial
language: python
python: 3.6
python: "3.6"
env:
- KERAS_BACKEND=tensorflow
- KERAS_BACKEND=tensorflow TF_KERAS=1
- KERAS_BACKEND=tensorflow TF_KERAS=1 TF_EAGER=1
- KERAS_BACKEND=tensorflow TF_KERAS=1 TF_2=1
- KERAS_BACKEND=theano THEANO_FLAGS=optimizer=fast_compile
global:
- COVERALLS_PARALLEL=true
matrix:
- KERAS_BACKEND=tensorflow
- KERAS_BACKEND=tensorflow TF_KERAS=1
install:
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
else
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
fi
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- conda config --set always_yes yes --set changeps1 no
Expand All @@ -24,10 +20,10 @@ install:
- pip install --upgrade pip
- pip install -r requirements.txt
- pip install -r requirements-dev.txt
- if [[ $TF_2 == "1" ]]; then pip install tensorflow==2.0.0-beta0; fi
- if [[ $KERAS_BACKEND == "theano" ]]; then pip install theano && conda install mkl mkl-service; fi
- pip install coveralls
script:
- ./test.sh
after_success:
coveralls
notifications:
webhooks: https://coveralls.io/webhook
3 changes: 0 additions & 3 deletions README.md
Expand Up @@ -7,10 +7,7 @@
![License](https://img.shields.io/pypi/l/keras-embed-sim.svg)

![](https://img.shields.io/badge/keras-tensorflow-blue.svg)
![](https://img.shields.io/badge/keras-theano-blue.svg)
![](https://img.shields.io/badge/keras-tf.keras-blue.svg)
![](https://img.shields.io/badge/keras-tf.keras/eager-blue.svg)
![](https://img.shields.io/badge/keras-tf.keras/2.0_beta-blue.svg)

\[[中文](https://github.com/CyberZHG/keras-embed-sim/blob/master/README.zh-CN.md)|[English](https://github.com/CyberZHG/keras-embed-sim/blob/master/README.md)\]

Expand Down
2 changes: 2 additions & 0 deletions keras_embed_sim/__init__.py
@@ -1 +1,3 @@
from .embeddings import *

__version__ = '0.8.0'
19 changes: 6 additions & 13 deletions keras_embed_sim/backend.py
@@ -1,23 +1,17 @@
import os
from distutils.util import strtobool

__all__ = [
'keras', 'utils', 'activations', 'applications', 'backend', 'datasets', 'engine',
'keras', 'utils', 'activations', 'applications', 'backend', 'datasets',
'layers', 'preprocessing', 'wrappers', 'callbacks', 'constraints', 'initializers',
'metrics', 'models', 'losses', 'optimizers', 'regularizers', 'TF_KERAS', 'EAGER_MODE'
'metrics', 'models', 'losses', 'optimizers', 'regularizers', 'TF_KERAS',
]

TF_KERAS = False
EAGER_MODE = False
TF_KERAS = strtobool(os.environ.get('TF_KERAS', '0'))

if 'TF_KERAS' in os.environ and os.environ['TF_KERAS'] != '0':
if TF_KERAS:
import tensorflow as tf
from tensorflow.python import keras
TF_KERAS = True
if 'TF_EAGER' in os.environ and os.environ['TF_EAGER'] != '0':
if int(tf.version.VERSION.split('.')[0]) < 2:
import tensorflow as tf
tf.enable_eager_execution()
EAGER_MODE = True
keras = tf.keras
else:
import keras

Expand All @@ -26,7 +20,6 @@
applications = keras.applications
backend = keras.backend
datasets = keras.datasets
engine = keras.engine
layers = keras.layers
preprocessing = keras.preprocessing
wrappers = keras.wrappers
Expand Down
2 changes: 1 addition & 1 deletion keras_embed_sim/embeddings.py
Expand Up @@ -22,7 +22,7 @@ def compute_mask(self, inputs, mask=None):
def call(self, inputs):
return [
super(EmbeddingRet, self).call(inputs),
K.identity(self.embeddings),
self.embeddings + 0.0,
]


Expand Down
33 changes: 23 additions & 10 deletions setup.py
@@ -1,30 +1,43 @@
import os
import re
import codecs
from setuptools import setup, find_packages

current_path = os.path.abspath(os.path.dirname(__file__))

with codecs.open('README.md', 'r', 'utf8') as reader:
long_description = reader.read()

def read_file(*parts):
with codecs.open(os.path.join(current_path, *parts), 'r', 'utf8') as reader:
return reader.read()

with codecs.open('requirements.txt', 'r', 'utf8') as reader:
install_requires = list(map(lambda x: x.strip(), reader.readlines()))

def get_requirements(*parts):
with codecs.open(os.path.join(current_path, *parts), 'r', 'utf8') as reader:
return list(map(lambda x: x.strip(), reader.readlines()))


def find_version(*file_paths):
version_file = read_file(*file_paths)
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError('Unable to find version string.')


setup(
name='keras-embed-sim',
version='0.7.0',
version=find_version('keras_embed_sim', '__init__.py'),
packages=find_packages(),
url='https://github.com/CyberZHG/keras-embed-sim',
license='MIT',
author='CyberZHG',
author_email='CyberZHG@gmail.com',
author_email='CyberZHG@users.noreply.github.com',
description='Calculate similarity with embedding',
long_description=long_description,
long_description=read_file('README.md'),
long_description_content_type='text/markdown',
install_requires=install_requires,
install_requires=get_requirements('requirements.txt'),
classifiers=(
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
),
Expand Down
2 changes: 1 addition & 1 deletion test.sh
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
pycodestyle --max-line-length=120 keras_embed_sim tests && \
nosetests --with-coverage --cover-html --cover-html-dir=htmlcov --cover-package=keras_embed_sim tests
nosetests --nocapture --with-coverage --cover-html --cover-html-dir=htmlcov --cover-package=keras_embed_sim tests

0 comments on commit b1ab67e

Please sign in to comment.