Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
amaiya committed Aug 2, 2019
2 parents 285ed3b + 17f54f5 commit 21ac7a5
Show file tree
Hide file tree
Showing 15 changed files with 737 additions and 28 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ 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.1.10 (2019-08-02)

### New:
- N/A

### Changed:
- For ```Learner.lr_find```, removed epochs and max_lr arguments and added lr_mult argument
Default lr_mult is 1.01, but can be changed to control size of sample being used
to estimate learning rate.
- Changed structure of examples folder

### Fixed:
- Resolved issue with ```utils.y_from_data``` not working correctly with DataFrameIterator objects.


## 0.1.9 (2019-08-01)

### New:
Expand Down
200 changes: 200 additions & 0 deletions examples/text/IMDb-fasttext.ipynb

Large diffs are not rendered by default.

File renamed without changes.
226 changes: 226 additions & 0 deletions examples/text/toxic_comments-fasttext.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"os.environ[\"CUDA_DEVICE_ORDER\"]=\"PCI_BUS_ID\";\n",
"os.environ[\"CUDA_VISIBLE_DEVICES\"]=\"0\" \n",
"import sys\n",
"sys.path.append('..')\n",
"import ktrain\n",
"from ktrain import vision as vis"
]
Expand Down Expand Up @@ -53,7 +52,7 @@
}
],
"source": [
"DATADIR = '../data/dogscats'\n",
"DATADIR = 'data/dogscats'\n",
"(train_data, val_data, preproc) = vis.images_from_folder(\n",
" datadir=DATADIR,\n",
" data_aug = vis.get_data_aug(horizontal_flip=True),\n",
Expand Down Expand Up @@ -238,7 +237,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
275 changes: 275 additions & 0 deletions examples/vision/planet-ResNet50.ipynb

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions ktrain/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def reset_weights(self, nosave=False, verbose=1):



def lr_find(self, start_lr=1e-7, epochs=5, verbose=1):
def lr_find(self, start_lr=1e-7, lr_mult=1.01, verbose=1):
"""
Plots loss as learning rate is increased.
Highest learning rate corresponding to a still
Expand All @@ -425,8 +425,7 @@ def lr_find(self, start_lr=1e-7, epochs=5, verbose=1):
Reference: https://arxiv.org/abs/1506.01186
Args:
epochs (int): maximum number of epochs to simulate training
If None, chosen automatically.
lr_mult (float): multiplication factor to increase LR.
start_lr (float): smallest lr to start simulation
verbose (bool): specifies how much output to print
Returns:
Expand All @@ -446,8 +445,7 @@ def lr_find(self, start_lr=1e-7, epochs=5, verbose=1):
try:
# track and plot learning rates
self.lr_finder = LRFinder(self.model)
self.lr_finder.find(self.train_data, start_lr=start_lr, end_lr=10,
epochs=epochs,
self.lr_finder.find(self.train_data, start_lr=start_lr, lr_mult=lr_mult,
workers=self.workers,
use_multiprocessing=self.use_multiprocessing,
verbose=verbose)
Expand Down
10 changes: 3 additions & 7 deletions ktrain/lroptimize/lrfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def on_batch_end(self, batch, logs):
K.set_value(self.model.optimizer.lr, lr)


def find(self, train_data, start_lr, end_lr, epochs=None, batch_size=U.DEFAULT_BS,
def find(self, train_data, start_lr, lr_mult=1.01, batch_size=U.DEFAULT_BS,
workers=1, use_multiprocessing=False, verbose=1):
"""
Track loss as learning rate is increased.
Expand All @@ -76,12 +76,8 @@ def find(self, train_data, start_lr, end_lr, epochs=None, batch_size=U.DEFAULT_B
use_gen = False
steps_per_epoch = np.ceil(num_samples/batch_size)

if epochs is None:
epochs = math.ceil(SAMPLE_SIZE/steps_per_epoch)


num_batches = epochs * steps_per_epoch
self.lr_mult = (end_lr / start_lr) ** (1 / num_batches)
epochs = 1024
self.lr_mult = lr_mult

# Save weights into a file
new_file, self._weightfile = tempfile.mkstemp()
Expand Down
10 changes: 5 additions & 5 deletions ktrain/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ def nclasses_from_data(data):

def y_from_data(data):
if is_iter(data):
if hasattr(data, 'classes'):
if hasattr(data, 'classes'): # DirectoryIterator
return to_categorical(data.classes)
elif hasattr(data, 'data'):
return data.data
elif hasattr(data, 'y'):
return data.y
elif hasattr(data, 'labels'): # DataFrameIterator
return data.labels
elif hasattr(data, 'y'): # NumpyArrayIterator
return to_categorical(data.y)
else:
raise Exception('could not determine number of classes from %s' % (type(data)))
else:
Expand Down
2 changes: 1 addition & 1 deletion ktrain/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__all__ = ['__version__']
__version__ = '0.1.9'
__version__ = '0.1.10'
4 changes: 2 additions & 2 deletions tutorial-03-image-classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@
"outputs": [],
"source": [
"y_pred = learner.model.predict_generator(val_data)\n",
"y_true = val_data._data"
"y_true = val_data.labels"
]
},
{
Expand Down Expand Up @@ -1544,7 +1544,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions tutorial-04-text-classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@
"source": [
"Finally, we will train our model for 8 epochs using ```autofit``` with a learning rate of 0.0007. Having explicitly specified the number of epochs, ```autofit``` will automatically employ a triangular learning rate policy. Our final ROC-AUC score is **0.98**.\n",
"\n",
"As shown in [this example notebook](https://github.com/amaiya/ktrain/blob/master/examples/toxic_comments-bigru.ipynb) on our GitHub project, even better results can be obtained using a Bidirectional GRU with pretrained word vectors (called ‘bigru’ in ktrain)"
"As shown in [this example notebook](https://github.com/amaiya/ktrain/blob/master/examples/text/toxic_comments-bigru.ipynb) on our GitHub project, even better results can be obtained using a Bidirectional GRU with pretrained word vectors (called ‘bigru’ in ktrain)"
]
},
{
Expand Down Expand Up @@ -785,7 +785,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 21ac7a5

Please sign in to comment.