Skip to content

Commit

Permalink
Add support for TF 2.16.1 stable, Ready for release.
Browse files Browse the repository at this point in the history
  • Loading branch information
feranick committed Mar 8, 2024
1 parent 2e8a7aa commit bc1e800
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Machine learning software for rapid spectral analysis. While Raman spectra were
- DNNClassifier (TensorFlow, TensorFlow-Lite)
- Convolutional Neural Networks (TensorFlow, TensorFlow-Lite)
- Required libraries for prediction:
- tensorflow (v.2.12 or higher - won't work with previous releases)
- Optional: tensorflow-lite (v.2.11 and higher)
- tensorflow (v2.13 or higher, v2.16.1 recommended)
- Optional: tensorflow-lite (v2.13 and higher, v2.16.1 recommended)
- Optional: [tensorflow-lite runtime](https://www.tensorflow.org/lite/guide/python)
- Optional: tensorflow-lite runtime with [Coral EdgeTPU](https://coral.ai/docs/accelerator/get-started/)

Expand All @@ -23,7 +23,7 @@ Installation
## Installation from available wheel package
If available from the main site, you can install SpectraKeras by running:

python3 -m pip install --upgrade spectrakeras-2023.12.22.3-py3-none-any.whl
python3 -m pip install --upgrade spectrakeras-2024.03.08.1-py3-none-any.whl

SpectraKeras_CNN and Spectrakeras_MLP are available directly from the command line.
NOTE: The Utilities in the `Utilities` folder are not included in the package, and can be run locally as needed.
Expand All @@ -50,7 +50,7 @@ This software requires Python (3.9 or higher). It has been tested with Python 3.
pydot
graphviz
h5py
tensorflow (>=2.12)
tensorflow (>=2.13)

In addition, these packages may be needed depending on your platform (via ```apt-get``` in debian/ubuntu or ```port``` in OSX):

Expand All @@ -62,9 +62,9 @@ These are found in Unix based systems using common repositories (apt-get for Deb
[TensorFlow](https://www.tensorflow.org) is needed only if flag is activated. Instructions for Linux and MacOS can be found in [TensorFlow installation page](https://www.tensorflow.org/install/). Pip installation is the easiest way to get going. Tested with TensorFlow 2.x (2.15 or higher preferred). TF 2.15 is the currently supported release.

Inference can be carried out using the regular tensorflow, or using [tensorflow-lite](https://www.tensorflow.org/lite/) for [quantized models](https://www.tensorflow.org/lite/performance/post_training_quantization). Loading times of tflite (direct or via [tflite-runtime](https://www.tensorflow.org/lite/guide/python)) are significantly faster than tensorflow with minimal loss in accuracy. SpectraKeras provides an option to convert tensorflow models to quantized tflite models. TFlite models have been tested in Linux x86-64, arm7 (including Raspberry Pi3) and aarm64, MacOS, Windows.
To use quantized models, TF 2.3 or higher is recommended.
To use quantized models, TF 2.13 or higher is recommended.

Inference using the [Coral EdgeTPU](https://coral.ai/) [tensorflow-lite](https://www.tensorflow.org/lite/) requires the [libedgetpu](https://github.com/google-coral/libedgetpu) libraries compatible with the supported and current version of `tflite-runtime` (version 2.15.0 or less), which is also required (Instructions and binaries can be found [here](https://github.com/feranick/TFlite-builds). More information on installation of such libraries at [Coral EdgeTPU](https://coral.ai/).
Inference using the [Coral EdgeTPU](https://coral.ai/) [tensorflow-lite](https://www.tensorflow.org/lite/) requires the [libedgetpu](https://github.com/google-coral/libedgetpu) libraries compatible with the supported and current version of `tflite-runtime` (version v2.13.0 or hiigher, v2.16.1 recommended), which is also required (Instructions and binaries can be found [here](https://github.com/feranick/TFlite-builds). More information on installation of such libraries at [Coral EdgeTPU](https://coral.ai/).

Usage (SpectraKeras)
===================
Expand Down
8 changes: 4 additions & 4 deletions SpectraKeras-web/SpectraKeras_CNN.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'''
**********************************************
* SpectraKeras_CNN Classifier and Regressor
* v2024.03.03.1
* v2024.03.08.1
* Uses: TensorFlow
* By: Nicola Ferralis <[email protected]>
**********************************************
Expand Down Expand Up @@ -223,7 +223,7 @@ def main():
def train(learnFile, testFile, flag):
dP = Conf()
import tensorflow as tf
if checkTFVersion("2.15.99"):
if checkTFVersion("2.16.0"):
import tensorflow.keras as keras
else:
if dP.kerasVersion == 2:
Expand Down Expand Up @@ -791,7 +791,7 @@ def printParam():
def plotActivationsTrain(model):
import matplotlib.pyplot as plt
import tensorflow as tf
if checkTFVersion("2.15.99"):
if checkTFVersion("2.16.0"):
import tensorflow.keras as keras
else:
if dP.kerasVersion == 2:
Expand Down Expand Up @@ -824,7 +824,7 @@ def plotActivationsTrain(model):
def plotActivationsPredictions(R, model):
print(" Saving activation plots...\n")
import matplotlib.pyplot as plt
if checkTFVersion("2.15.99"):
if checkTFVersion("2.16.0"):
import tensorflow as tf
import tensorflow.keras as keras
else:
Expand Down
8 changes: 4 additions & 4 deletions SpectraKeras-web/libSpectraKeras.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'''
**********************************************
* libSpectraKeas - Library for SpectraKeras
* v2024.03.03.1
* v2024.03.08.1
* Uses: TensorFlow
* By: Nicola Ferralis <[email protected]>
**********************************************
Expand Down Expand Up @@ -87,14 +87,14 @@ def loadModel(dP):
model = tflite.Interpreter(model_path=os.path.splitext(dP.model_name)[0]+'_edgetpu.tflite',
experimental_delegates=[tflite.load_delegate(dP.edgeTPUSharedLib,{})])
except:
print(" Coral Edge TPU not found. Please make sure it's connected and Tflite-runtime is v2.11.1 or lower.")
print(" Coral Edge TPU not found. Please make sure it's connected and Tflite-runtime matches the TF version that is installled.")
else:
model = tflite.Interpreter(model_path=os.path.splitext(dP.model_name)[0]+'.tflite')
model.allocate_tensors()
else:
getTFVersion(dP)
import tensorflow as tf
if checkTFVersion("2.15.99"):
if checkTFVersion("2.16.0"):
import tensorflow.keras as keras
else:
if dP.kerasVersion == 2:
Expand Down Expand Up @@ -187,7 +187,7 @@ def representative_dataset_gen():
#************************************
def plotWeights(dP, En, A, model, type):
import matplotlib.pyplot as plt
if checkTFVersion("2.15.99"):
if checkTFVersion("2.16.0"):
import tensorflow as tf
import tensorflow.keras as keras
else:
Expand Down
8 changes: 4 additions & 4 deletions SpectraKeras/SpectraKeras_CNN.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'''
**********************************************
* SpectraKeras_CNN Classifier and Regressor
* v2024.03.03.1
* v2024.03.08.1
* Uses: TensorFlow
* By: Nicola Ferralis <[email protected]>
**********************************************
Expand Down Expand Up @@ -223,7 +223,7 @@ def main():
def train(learnFile, testFile, flag):
dP = Conf()
import tensorflow as tf
if checkTFVersion("2.15.99"):
if checkTFVersion("2.16.0"):
import tensorflow.keras as keras
else:
if dP.kerasVersion == 2:
Expand Down Expand Up @@ -791,7 +791,7 @@ def printParam():
def plotActivationsTrain(model):
import matplotlib.pyplot as plt
import tensorflow as tf
if checkTFVersion("2.15.99"):
if checkTFVersion("2.16.0"):
import tensorflow.keras as keras
else:
if dP.kerasVersion == 2:
Expand Down Expand Up @@ -824,7 +824,7 @@ def plotActivationsTrain(model):
def plotActivationsPredictions(R, model):
print(" Saving activation plots...\n")
import matplotlib.pyplot as plt
if checkTFVersion("2.15.99"):
if checkTFVersion("2.16.0"):
import tensorflow as tf
import tensorflow.keras as keras
else:
Expand Down
4 changes: 2 additions & 2 deletions SpectraKeras/SpectraKeras_MLP.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'''
**********************************************
* SpectraKeras_MLP Classifier and Regressor
* v2024.03.03.1
* v2024.03.08.1
* Uses: TensorFlow
* By: Nicola Ferralis <[email protected]>
**********************************************
Expand Down Expand Up @@ -199,7 +199,7 @@ def main():
def train(learnFile, testFile):
dP = Conf()
import tensorflow as tf
if checkTFVersion("2.15.99"):
if checkTFVersion("2.16.0"):
import tensorflow.keras as keras
else:
if dP.kerasVersion == 2:
Expand Down
8 changes: 4 additions & 4 deletions SpectraKeras/libSpectraKeras.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'''
**********************************************
* libSpectraKeas - Library for SpectraKeras
* v2024.03.03.1
* v2024.03.08.1
* Uses: TensorFlow
* By: Nicola Ferralis <[email protected]>
**********************************************
Expand Down Expand Up @@ -87,14 +87,14 @@ def loadModel(dP):
model = tflite.Interpreter(model_path=os.path.splitext(dP.model_name)[0]+'_edgetpu.tflite',
experimental_delegates=[tflite.load_delegate(dP.edgeTPUSharedLib,{})])
except:
print(" Coral Edge TPU not found. Please make sure it's connected and Tflite-runtime is v2.11.1 or lower.")
print(" Coral Edge TPU not found. \n Please make sure it's connected and Tflite-runtime matches the TF version that is installled.")
else:
model = tflite.Interpreter(model_path=os.path.splitext(dP.model_name)[0]+'.tflite')
model.allocate_tensors()
else:
getTFVersion(dP)
import tensorflow as tf
if checkTFVersion("2.15.99"):
if checkTFVersion("2.16.0"):
import tensorflow.keras as keras
else:
if dP.kerasVersion == 2:
Expand Down Expand Up @@ -187,7 +187,7 @@ def representative_dataset_gen():
#************************************
def plotWeights(dP, En, A, model, type):
import matplotlib.pyplot as plt
if checkTFVersion("2.15.99"):
if checkTFVersion("2.16.0"):
import tensorflow as tf
import tensorflow.keras as keras
else:
Expand Down
2 changes: 1 addition & 1 deletion SpectraKeras/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include = [

[project]
name = "SpectraKeras"
version = "v2024.03.03.1"
version = "v2024.03.08.1"
dependencies = ["numpy", "h5py", "tensorflow", "pydot", "graphviz","scipy","tf-keras"]
authors = [{ name="Nicola Ferralis", email="[email protected]" },]
description = "Machine learning for scientific spectra"
Expand Down

0 comments on commit bc1e800

Please sign in to comment.