Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
amaiya committed Dec 10, 2019
2 parents 339db28 + 94a23b7 commit 11d7630
Show file tree
Hide file tree
Showing 62 changed files with 201 additions and 11,487 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ Most recent releases are shown at the top. Each release shows:
- **Changed**: Additional parameters, changes to inputs or outputs, etc
- **Fixed**: Bug fixes that don't change documented behaviour

## 0.7.0 (2019-12-10)

### New:
- *ktrain* now uses tf.keras (`tensorflow>=1.14,<=2.0) instead of stand-alone Keras.

### Changed:
- N/A

### Fixed:
- N/A


## 0.6.2 (2019-12-02)

### New:
Expand Down
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@



### News and Announcements
- **2019-12-10:**
- ***ktrain*** **v0.7.x is released and now uses TensorFlow Keras** (i.e., `tf.keras`) instead of stand-alone Keras. If you're using custom Keras models with *ktrain*, you must change all `keras` references to `tensorflow.keras`. That is, don't import Keras like this: `from keras.layers import Dense`. Do this instead: `from tensorflow.keras.layers import Dense`. If you mix calls to tf.keras with Keras, you will experience problems. Supported versions of TensorFlow include 1.14 and 2.0.
- **2019-11-12:**
- *ktrain* v0.6.x is released and includes pre-canned support for [learning from unlabeled or partially labeled text data](https://nbviewer.jupyter.org/github/amaiya/ktrain/blob/master/tutorial-05-learning_from_unlabeled_text_data.ipynb).
- **2019-10-16:**
- *ktrain* v0.5.x is released and includes pre-canned support for [node classification in graphs](https://nbviewer.jupyter.org/github/amaiya/ktrain/blob/master/examples/graphs/hateful_twitter_users-GraphSAGE.ipynb).
- **Coming Soon**:
- better support for custom data formats and models
- support for using *ktrain* with `tf.keras` and TensorFlow 2.0
- ability to train [HuggingFace Transformer models](https://github.com/huggingface/transformers) within *ktrain*



----


Expand Down Expand Up @@ -177,9 +183,20 @@ Additional examples can be found [here](https://github.com/amaiya/ktrain/tree/ma

### Installation

```
pip3 install ktrain
```
Make sure pip is up-to-date with: `pip3 install -U pip`.

1. Ensure Tensorflow 1.14 or TensorFlow 2 [is installed](https://www.tensorflow.org/install/pip?lang=python3) if it is not already

> For GPU: `pip3 install "tensorflow_gpu>=1.14,<=2"`
> For CPU: `pip3 install "tensorflow>=1.14,<=2"`

2. Install *ktrain*: `pip3 install ktrain`

The *ktrain* package can be used with TensorFlow versions 1.14 and 2.0. If using TensorFlow 2.0, *ktrain*
presently runs in 1.x mode using [tf.compat.v1.disable_v2_behavior](https://www.tensorflow.org/api_docs/python/tf/compat/v1/disable_v2_behavior). In the future, this will be removed and **only** TensorFlow 2 will be supported.


<!--
### Requirements
Expand All @@ -197,8 +214,7 @@ The following software/libraries should be installed:
-->



This code was tested on Ubuntu 18.04 LTS using Keras 2.2.4 with a TensorFlow 1.14 backend.
This code was tested on Ubuntu 18.04 LTS using TensorFlow 1.14 and TensorFlow 2 (Keras version 2.2.4-tf).

----
**Creator: [Arun S. Maiya](http://arun.maiya.net)**
Expand Down
4 changes: 2 additions & 2 deletions examples/text/IMDb-fasttext.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
"metadata": {},
"outputs": [],
"source": [
"from keras.models import Sequential\n",
"from keras.layers import Dense, Embedding, GlobalAveragePooling1D\n",
"from tensorflow.keras.models import Sequential\n",
"from tensorflow.keras.layers import Dense, Embedding, GlobalAveragePooling1D\n",
"def get_model():\n",
" model = Sequential()\n",
" model.add(Embedding(20000+1, 50, input_length=400)) # add 1 for padding token\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/text/toxic_comments-bigru.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
"outputs": [],
"source": [
"# define a custom callback for ROC-AUC\n",
"from keras.callbacks import Callback\n",
"from tensorflow.keras.callbacks import Callback\n",
"from sklearn.metrics import roc_auc_score\n",
"class RocAucEvaluation(Callback):\n",
" def __init__(self, validation_data=(), interval=1):\n",
Expand Down
3 changes: 1 addition & 2 deletions examples/vision/cifar10-WRN22.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"import os\n",
"os.environ[\"CUDA_DEVICE_ORDER\"]=\"PCI_BUS_ID\";\n",
"os.environ[\"CUDA_VISIBLE_DEVICES\"]=\"0\"; \n",
"import sys\n",
"sys.path.append('..')"
"import sys"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions examples/vision/mnist-WRN22.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"import os\n",
"os.environ[\"CUDA_DEVICE_ORDER\"]=\"PCI_BUS_ID\";\n",
"os.environ[\"CUDA_VISIBLE_DEVICES\"]=\"0\" \n",
"import sys\n",
"sys.path.append('..')"
"import sys"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion ktrain/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ def _load_model(fpath, preproc=None, train_data=None):
elif (preproc and (isinstance(preproc, NodePreprocessor) or \
type(preproc).__name__ == 'NodePreprocessor')) or \
train_data and U.is_nodeclass(data=train_data):
from .graph.stellargraph.layer import MeanAggregator
from stellargraph.layer import MeanAggregator
custom_objects={'MeanAggregator': MeanAggregator}
try:
model = load_model(fpath, custom_objects=custom_objects)
Expand Down
8 changes: 0 additions & 8 deletions ktrain/graph/data.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#import networkx as nx
#import pandas as pd
#import stellargraph as sg
#from stellargraph.mapper import GraphSAGENodeGenerator, GraphSAGELinkGenerator
#from sklearn import preprocessing, feature_extraction, model_selection
#from stellargraph.data import EdgeSplitter


from ..imports import *
from .. import utils as U
from .node_generator import NodeSequenceWrapper
Expand Down
10 changes: 5 additions & 5 deletions ktrain/graph/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from ..imports import *
from .. import utils as U
from .node_generator import NodeSequenceWrapper
from . import stellargraph as sg
from .stellargraph.mapper import GraphSAGENodeGenerator, GraphSAGELinkGenerator
from .stellargraph.layer import GraphSAGE

import stellargraph as sg
from stellargraph.mapper import GraphSAGENodeGenerator, GraphSAGELinkGenerator
from stellargraph.layer import GraphSAGE



Expand Down Expand Up @@ -61,7 +60,8 @@ def graph_node_classifier(name, train_data, layer_sizes=[32,32], verbose=1):
bias=True,
dropout=0.5,
)
x_inp, x_out = graphsage_model.default_model(flatten_output=True)
#x_inp, x_out = graphsage_model.default_model(flatten_output=True)
x_inp, x_out = graphsage_model.build()
prediction = Dense(units=num_classes, activation=activation)(x_out)
model = Model(inputs=x_inp, outputs=prediction)
model.compile(optimizer='adam',
Expand Down
4 changes: 2 additions & 2 deletions ktrain/graph/node_generator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .stellargraph.mapper import node_mappers
from stellargraph.mapper import node_mappers

class NodeSequenceWrapper(node_mappers.NodeSequence):
def __init__(self, node_seq):
if not isinstance(node_seq, node_mappers.NodeSequence):
raise ValueError('node_seq must by a stellargraph NodeSequene object')
raise ValueError('node_seq must by a stellargraph NodeSequence object')
self.node_seq = node_seq
self.targets = node_seq.targets
self.generator = node_seq.generator
Expand Down
6 changes: 3 additions & 3 deletions ktrain/graph/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from ..preprocessor import Preprocessor
from .node_generator import NodeSequenceWrapper

from . import stellargraph as sg
from .stellargraph.mapper import GraphSAGENodeGenerator, GraphSAGELinkGenerator
from .stellargraph.layer import GraphSAGE
import stellargraph as sg
from stellargraph.mapper import GraphSAGENodeGenerator, GraphSAGELinkGenerator
from stellargraph.layer import GraphSAGE



Expand Down
45 changes: 0 additions & 45 deletions ktrain/graph/stellargraph/__init__.py

This file was deleted.

23 changes: 0 additions & 23 deletions ktrain/graph/stellargraph/core/__init__.py

This file was deleted.

0 comments on commit 11d7630

Please sign in to comment.