Saravanan666/pypi-org huggingface dataset:
Package: keras-model-extract
Keras Model ExtractThis is a small utility library to access Keras/TensorFlow model's structure/tree and do stuff with it.Currently there isn't a straight-forward way to do this without manually going through the model layers.It currently supports:Model tree iteration (BFS-like)Accessing node parents, node children, node output typeAccessing source layersNode properties:children: children nodes (sub-layers)parent_names: unique names of parent nodesshape: layer output shapename: unique layer name (from TF/Keras)__layer: reference to the instance of the layer (ifinclude_layer_refisTrue)How it works:It creates a pure Python tree clone of your model which is easy to walk through.InstallationThis package has no depenedencies.pip install keras-model-extractExample useThis examples show how to iterate through a model and print all the nodes.>>> from keras_model_extract import copy_model_tree, iterate
>>> from keras.applications.vgg16 import VGG16
>>> model = VGG16()
>>> nodes = copy_model_tree(model)
>>> nodes
{'input_1': input_1, 'block1_conv1': block1_conv1, 'block1_conv2': block1_conv2, 'block1_pool': block1_pool, 'block2_conv1': block2_conv1, 'block2_conv2': block2_conv2, 'block2_pool': block2_pool, 'block3_conv1': block3_conv1, 'block3_conv2': block3_conv2, 'block3_conv3': block3_conv3, 'block3_pool': block3_pool, 'block4_conv1': block4_conv1, 'block4_conv2': block4_conv2, 'block4_conv3': block4_conv3, 'block4_pool': block4_pool, 'block5_conv1': block5_conv1, 'block5_conv2': block5_conv2, 'block5_conv3': block5_conv3, 'block5_pool': block5_pool, 'flatten': flatten, 'fc1': fc1, 'fc2': fc2, 'predictions': predictions}
>>> nodes['input_1'].children
[block1_conv1]
>>> nodes['block4_pool'].parent_names
['block4_conv3']
>>> nodes['block4_pool'].shape
(None, 14, 14, 512)
>>> iterate(nodes['input_1'], lambda layer: print(layer))
input_1
block1_conv1
block1_conv2
block1_pool
block2_conv1
block2_conv2
block2_pool
block3_conv1
block3_conv2
block3_conv3
block3_pool
block4_conv1
block4_conv2
block4_conv3
block4_pool
block5_conv1
block5_conv2
block5_conv3
block5_pool
flatten
fc1
fc2
predictions
Package: keras-models
Keras Models HubThis repo aims at providing bothreusableKeras Models andpre-trainedmodels, which could easily integrated into your projects.Installpipinstallkeras-modelsIf you will using the NLP models, you need run one more command:python-mspacydownloadxx_ent_wiki_smUsage GuideImportimport kearasmodelsExamplesReusable ModelsLinearModelDNNCNNfromkeras_models.modelsimportCNN# fake dataX=np.random.normal(0,1.0,size=500*100*100*3).reshape(500,100,100,3)w1=np.random.normal(0,1.0,size=100)w2=np.random.normal(0,1.0,size=3)Y=np.dot(np.dot(np.dot(X,w2),w1),w1)+np.random.randint(1)# initialize & train modelmodel=CNN(input_shape=X.shape[1:],filters=[32,64],kernel_size=(2,2),pool_size=(3,3),padding='same',r_dropout=0.25,num_classes=1)model.compile(optimizer='adam',loss=mean_squared_error,metrics=['mae','mse'])model.summary()model.fit(X,Y,batch_size=16,epochs=100,validation_split=0.1)SkipGramWideDeepPre-trained ModelsVGG16_Places365This model is forked fromGKalliatakis/Keras-VGG16-places365andCSAILVision/places365fromkeras_models.models.pretrainedimportvgg16_places365labels=vgg16_places365.predict(['your_image_file_pathname.jpg','another.jpg'],n_top=3)# Example Result: labels = [['cafeteria', 'food_court', 'restaurant_patio'], ['beach', 'sand']]ModelsLinearModelDNNWideDeepTextCNNTextDNNSkipGramResNetVGG16_Places365 [pre-trained]working on more modelsCitationWideDeepCheng H T, Koc L, Harmsen J, et al. 
Wide & deep learning for recommender systems[C]
Proceedings of the 1st workshop on deep learning for recommender systems. ACM, 2016: 7-10.TextCNNKim Y. 
Convolutional neural networks for sentence classification[J]. 
arXiv preprint arXiv:1408.5882, 2014.SkipGramMikolov T, Chen K, Corrado G, et al. 
Efficient estimation of word representations in vector space[J]. 
arXiv preprint arXiv:1301.3781, 2013.VGG16_Places365Zhou, B., Lapedriza, A., Khosla, A., Oliva, A., & Torralba, A.
Places: A 10 million Image Database for Scene Recognition
IEEE Transactions on Pattern Analysis and Machine IntelligenceResNetHe K, Zhang X, Ren S, et al. 
Deep residual learning for image recognition[C]
Proceedings of the IEEE conference on computer vision and pattern recognition. 2016: 770-778.ContributionPlease submit PR if you want to contribute, or submit issues for new model requirements.
Package: keras-mri
Keras MRIKeras MRI is a neural network visualization tool for Keras. This is still in Beta and some networks (e.g. RNNs and 3D CNNs) and types of layers are not yet supported.Installpipinstallkeras-mriUsageimportkmrifromkeras.modelsimportSequentialfromkeras.layersimportDensemodel=Sequential([Dense(8,input_shape=(3,))])input_batch=[[1,2,3],[7,8,9]]kmri.visualize_model(model,input_batch)Once this is running navigate tohttp://127.0.0.1:5000/ExamplesThe examples folder contains models that demonstrate keras-mri usage. To run one of the examples run the following from one of the example folderspipinstall-rrequirements.txt
pythonmain.pychrome-dinoSimple reinforcement learning model that learned to play the dinosaur game in chrome. Demonstrates visualizing a convolutional neural network with multiple inputs. This is based onchrome-dino-ai.img-classifierDemonstrates using keras-mri to visualize standard image classifieres (VGG, MobileNet, and ResNet).DevelopmentInstall package locallypip install -e .Deploy# increase version number in setup.py
# Move unrelease changes to next version in changelog.md
# commit, tag with vx.x.x, and push
# Delete build, dist, and egg-info
python setup.py sdist bdist_wheel
python -m twine upload dist/*
Package: keras-multilabel-embedding
keras-multilabel-embeddingThe package contains a TensorFlow2/Keras class to train an Embedding
matrix for multi-label inputs, i.e. instead of 1 ID per token (one hot
encoding), N IDs per token can be provided as model input.An PyTorch implementation can be found here:https://github.com/ulf1/torch-multilabel-embedding(pip installtorch-multilabel-embedding)UsageMulti-label embeddings with fixed number of labelsimportkeras_multilabel_embeddingastmlimporttensorflowastf# a sequence of multi-label data pointsx_ids=[[1,2,4],[0,1,2],[2,1,4],[3,2,1]]x_ids=tf.constant(x_ids)# initialize layerlayer=tml.MultiLabelEmbedding(vocab_size=5,embed_size=300,random_state=42)# predicty=layer(x_ids)Multi-label embeddings with variable number of labelsimportkeras_multilabel_embeddingastmlimporttensorflowastf# a sequence of multi-label data pointsx_ids=[[1,2,4],[0,1,2],[2,1],[3]]# initialize layerlayer=tml.MultiLabelEmbedding(vocab_size=5,embed_size=300,random_state=42)# predicty=layer(x_ids)AppendixInstallationThekeras-multilabel-embeddinggit
repois available
asPyPi
packagepipinstallkeras-multilabel-embeddingpipinstallgit+ssh://git@github.com/ulf1/keras-multilabel-embedding.gitInstall a virtual environmentpython3-mvenv.venvsource.venv/bin/activatepipinstall--upgradepippipinstall-rrequirements.txt--no-cache-dirpipinstall-rrequirements-dev.txt--no-cache-dirpipinstall-rrequirements-demo.txt--no-cache-dir(If your git repo is stored in a folder with whitespaces, then don’t use
the subfolder.venv. Use an absolute path without whitespaces.)Python commandsJupyter for the examples:jupyter labCheck syntax:flake8--ignore=F401--exclude=$(grep-v'^#'.gitignore | xargs | sed-e's//,/g')Run Unit Tests:PYTHONPATH=. pytestPublishpandocREADME.md--frommarkdown--torst-s-oREADME.rstpythonsetup.pysdisttwineupload-rpypidist/*Clean upfind.-typef-name"*.pyc"|xargsrmfind.-typed-name"__pycache__"|xargsrm-rrm-r.pytest_cacherm-r.venvSupportPleaseopen an
issuefor support.ContributingPlease contribute usingGithub
Flow. Create a branch,
add commits, andopen a pull
request.
Package: keras-mxnet
Keras is a high-level neural networks API,
written in Python. Keras-MXNet is capable of running on top of
high performance, scalable Apache MXNet deep learning engine.Use Keras-MXNet if you need a deep learning library that:Allows for easy and fast prototyping
(through user friendliness, modularity, and extensibility).Supports both convolutional networks and recurrent networks,
as well as combinations of the two.Runs seamlessly on CPU, one GPU and multi-GPU.Read the Keras documentation at:https://keras.io/Read the Keras-MXNet documentation at:https://github.com/awslabs/keras-apache-mxnet/tree/master/docs/mxnet_backendFor a detailed overview of what makes Keras special, see:https://keras.io/why-use-keras/Keras is compatible with Python 2.7-3.6
and is distributed under the MIT liense.
Package: keras-nalu
Keras NALU (Neural Arithmetic Logic Units)Keras implementation of a NALU layer (Neural Arithmetic Logic Units).
See:https://arxiv.org/pdf/1808.00508.pdf.Installationpip install keras-naluUsagefromkeras.layersimportInputfromkeras.modelsimportModelfromkeras.optimizersimportRMSpropfromkeras_nalu.naluimportNALU# Your datasetX_test=...# Interpolation dataY_test=...# Interpolation dataX_validation=...# Extrapolation data (validation)Y_validation=...# Extrapolation data (validation)X_test=...# Extrapolation data (test)Y_test=...# Extrapolation data (test)# Hyper parametersepoch_count=1000learning_rate=0.05sequence_len=100inputs=Input(shape=(sequence_len,))hidden=NALU(units=2)(inputs)hidden=NALU(units=2)(hidden)outputs=NALU(units=1)(hidden)model=Model(inputs=inputs,outputs=outputs)model.summary()model.compile(loss='mse',optimizer=RMSprop(lr=learning_rate))model.fit(batch_size=256,epochs=epoch_count,validation_data=(X_validation,Y_validation),x=X_train,y=Y_train,)extrapolation_loss=model.evaluate(batch_size=256,x=X_test,y=Y_test,)OptionscellCell to use in the NALU layer. May be 'a' (addition/subtraction), 'm' (multiplication/division/power), or None which, will apply a gating function to toggle between 'a' or 'm'.Default:NoneType:?('a' | 'm' | None)eEpsilon value added to inputs in order to prevent calculating the log of zero.Default:1e-7Type:?float
Package: keras-notify
Keras Notify CallbackA Tensorflow/Keras callback which sends information about your model training, on various messaging platforms.InstallationUsingpip:pipinstallkeras-notifyUsageImport the required module and add it to the list callbacks while training your model.Example:>>>fromkeras-notifyimportTelegramCallback>>>telegram_callback=TelegramCallback('<BotToken>','<ChatID>','CNN Model',['loss','val_loss'],['accuracy','val_accuracy'],True)>>>model.fit(x_train,y_train,batch_size=32,epochs=10,validation_data=(x_test,y_test),callbacks=[telegram_callback])TelegramCreate a telegram bot using BotFatherSearch for @BotFather on telegram.Send/helpto get list of all commands.Send/newbotto create a new bot and complete the setup.Copy thebot tokenafter creating the bot.Get thechat IDSearch for the bot you created and send it any random message.Go to this URLhttps://api.telegram.org/bot<BOT_TOKEN>/getUpdates(replace <BOT_TOKEN> with your bot token)Copy thechat idof the user you want to send messages to.You receive thechat idonly if you send the message first and then go to the above url.Use theTelegramCallback()class.TelegramCallback(bot_token=None,chat_id=None,modelName='model',loss_metrics=['loss'],acc_metrics=[],getSummary=False):Arguments:bot_token: unique token of Telegram bot{str}chat_id: Telegram chat id you want to send message to{str}modelName: name of your model{str}loss_metrics: loss metrics you want in the loss graph{list of strings}acc_metrics: accuracy metrics you want in the accuracy graphs{list of strings}getSummary: Do you want message for each epoch (False) or a single message containing information about all epochs (True).{bool}SlackCreate a Slack workspaceCreate a new channelSearch for theIncoming Webhooksin the Apps and install it.Copy theWebhook URLUse theSlackCallback()class.SlackCallback(bot_token=None,chat_id=None,modelName='model',loss_metrics=['loss'],acc_metrics=[],getSummary=False):Arguments:webhookURL: unique webhook URL of the app{str}channel:  channel name or username you want to send message to{str}modelName: name of your model{str}loss_metrics: loss metrics you want in the loss graph{list of strings}acc_metrics: accuracy metrics you want in the accuracy graph{list of strings}getSummary: Do you want message for each epoch (False) or a single message containing information about all epochs (True).{bool}Sending images in Slack is not supported currently.ToDoWhatsAppE-MailZulipMessages
Package: keras-one-cycle-lr
Keras-training-toolsImplementation of some of the very effective tools for training Deep Learning (DL) models that I came across while doing the fastai course onPractical Deep Learning for Coders.The tools were first presented in the following papers by Leslie N. Smith:LR Finder:A disciplined approach to neural network hyper-parameters: Part 1 -- learning rate, batch size, momentum, and weight decayOne Cycle Scheduler:Cyclical Learning Rates for Training Neural NetworksMy implementations are a port of the code infastai library(originally, based on Pytorch) to Keras and are heavily inspired by some of earlier efforts in this direction:https://github.com/surmenok/keras_lr_finderhttps://github.com/titu1994/keras-one-cycleHere's another article I referred to:How Do You Find A Good Learning Rateby Sylvain Gugger of fastai which provides an intuitive understanding of how fastai's LR finder works.I'll keep updating this repository with the new tools I come across that could be practically useful for training a DL model.
Package: keras-on-lstm
Keras Ordered Neurons LSTM[中文|English]Unofficial implementation ofON-LSTM.Installpipinstallkeras-ordered-neuronsUsageBasicSame asLSTMexcept that an extra argumentchunk_sizeshould be given:fromkeras.modelsimportSequentialfromkeras.layersimportEmbedding,Bidirectional,Densefromkeras_ordered_neuronsimportONLSTMmodel=Sequential()model.add(Embedding(input_shape=(None,),input_dim=10,output_dim=100))model.add(Bidirectional(ONLSTM(units=50,chunk_size=5)))model.add(Dense(units=2,activation='softmax'))model.compile(optimizer='adam',loss='sparse_categorical_crossentropy')model.summary()DropConnectSetrecurrent_dropconnectto a non-zero value to enable drop-connect for recurrent weights:fromkeras_ordered_neuronsimportONLSTMONLSTM(units=50,chunk_size=5,recurrent_dropconnect=0.2)Expected Split PointsSetreturn_splitstoTrueif you want to know the expected split points of master forget gate and master input gate.fromkeras.modelsimportModelfromkeras.layersimportInput,Embeddingfromkeras_ordered_neuronsimportONLSTMinputs=Input(shape=(None,))embed=Embedding(input_dim=10,output_dim=100)(inputs)outputs,splits=ONLSTM(units=50,chunk_size=5,return_sequences=True,return_splits=True)(embed)model=Model(inputs=inputs,outputs=splits)model.compile(optimizer='adam',loss='mse')model.summary(line_length=120)tf.kerasAddTF_KERAS=1to environment variables if you are usingtensorflow.python.keras.
Package: keras-ordered-neurons
Keras Ordered Neurons LSTM[中文|English]Unofficial implementation ofON-LSTM.Installpipinstallkeras-ordered-neuronsUsageBasicSame asLSTMexcept that an extra argumentchunk_sizeshould be given:fromtensorflow.keras.modelsimportSequentialfromtensorflow.keras.layersimportEmbedding,Bidirectional,Densefromkeras_ordered_neuronsimportONLSTMmodel=Sequential()model.add(Embedding(input_shape=(None,),input_dim=10,output_dim=100))model.add(Bidirectional(ONLSTM(units=50,chunk_size=5)))model.add(Dense(units=2,activation='softmax'))model.compile(optimizer='adam',loss='sparse_categorical_crossentropy')model.summary()DropConnectSetrecurrent_dropconnectto a non-zero value to enable drop-connect for recurrent weights:fromkeras_ordered_neuronsimportONLSTMONLSTM(units=50,chunk_size=5,recurrent_dropconnect=0.2)Expected Split PointsSetreturn_splitstoTrueif you want to know the expected split points of master forget gate and master input gate.fromtensorflow.keras.modelsimportModelfromtensorflow.keras.layersimportInput,Embeddingfromkeras_ordered_neuronsimportONLSTMinputs=Input(shape=(None,))embed=Embedding(input_dim=10,output_dim=100)(inputs)outputs,splits=ONLSTM(units=50,chunk_size=5,return_sequences=True,return_splits=True)(embed)model=Model(inputs=inputs,outputs=splits)model.compile(optimizer='adam',loss='mse')model.summary(line_length=120)
Package: keras-pbar
Keras Progressbar with TQDM-like API.I'm a big fan of how Keras' progressbar looks, but I was annoyed,
that there is no way to use it the same as TQDM progressbar.
So, I published this tiny module, in order to avoid copy-pasting it
in every my project.Example usageimporttimeimportpandasaspdfromkeras_pbarimportkeras_pbardf=pd.read_csv("data.csv")foridentifier,slicedinkeras_pbar(df.group_by("id")):# Do some time consuming processing.time.sleep(2)NotesIt does not directly depend ontensorflow, so you can install it without.
But probably during import time, it will fail, whenkerastries to importtensorlfow.
Package: keras-pickle-wrapper
# `keras_pickle_wrapper`This small library exposes a KerasPickleWrapper class that allows keras models to be pickled, and even used across multiprocessing (or with a library like [job\_stream](https://github.com/wwoods/job_stream)).It won't be necessary if https://github.com/fchollet/keras/issues/789 is ever properly resolved.## Installation`pip install keras-pickle-wrapper`## Usage```pythonimport kerasimport pickleimport numpy as npfrom keras_pickle_wrapper import KerasPickleWrapperins = keras.layers.Input((2,))x = insx = keras.layers.Dense(3)(x)x = keras.layers.Dense(1)(x)m = keras.models.Model(inputs=ins, outputs=x)m.compile(loss='mse', optimizer='sgd')# Wrap a compiled modelmw = KerasPickleWrapper(m)# Calling the object returns the wrapped Keras modelmw().fit([[0,0], [0,1], [1,0], [1,1]], [[0], [1], [1], [0]])# Pickle / unpickle the wrapperdata = pickle.dumps(mw)mw2 = pickle.loads(data)output_1 = mw().predict(np.asarray([[0, 0]]))output_2 = mw2().predict(np.asarray([[0, 0]]))# You can unload the object from memory as wellmw.unload()# The object will remain unloaded until requested againoutput_3 = mw().predict(np.asarray([[0, 0]]))print("All outputs:")print(output_1)print(output_2)print(output_3)# If using tensorflow and pickling / unpickling a lot, be sure to clear the# session:keras.backend.clear_session()# When using a custom layer class, be sure to register it so the pickler worksclass MyLayer(keras.layers.Layer):pass  # ...KerasPickleWrapper.register(MyLayer)```If your model takes 1GB of RAM, the default approach should require 2GB additional RAM to encode, as it dumps to shared memory by default.  To disable this, set `KerasPickleWrapper.NO_SHM = True`.  Temporary files will then be written to the standard temporary directory.  Using `KerasPickleWrapper.unload(clear_session=True)` prior to pickling combined with `NO_SHM` should eliminate excess memory consumption, but clears the session (session clearing only applies to Tensorflow at the moment).## Changelog* 2018-7-17 - Fix for Python 2 in setup.py (FileNotFoundError not existing in Python 2.7), up to V1.0.5.* 2017-9-19 - Fix for Python 2, up to V1.0.3.* 2017-8-17 - Renamed to keras-pickle-wrapper because PyPI.  V1.0.2.* 2017-8-17 - Packaged up KerasWrapper for PyPI distribution.
Package: keras-piecewise
Keras PiecewiseA wrapper layer for splitting and accumulating sequential data.Installpipinstallkeras-piecewise-poolingUsagePiecewiseimportkerasimportkeras.backendasKimportnumpyasnpfromkeras_piecewiseimportPiecewiseclassAvePool1D(keras.layers.Layer):def__init__(self,**kwargs):super(AvePool1D,self).__init__(**kwargs)defcall(self,inputs):returnK.sum(inputs,axis=1)/K.cast(K.shape(inputs)[1],K.floatx())defcompute_output_shape(self,input_shape):return(input_shape[0],)+input_shape[2:]data=[[[1,3,2,5],[7,9,2,3],[0,1,7,2],[4,7,2,5]]]positions=[[1,3,4]]piece_num=len(positions[0])data_input=keras.layers.Input(shape=(None,None))position_input=keras.layers.Input(shape=(piece_num,),dtype='int32')pool_layer=Piecewise(AvePool1D())([data_input,position_input])model=keras.models.Model(inputs=[data_input,position_input],outputs=pool_layer)model.compile(optimizer=keras.optimizers.Adam(),loss=keras.losses.mean_squared_error)model.summary()print(model.predict([np.asarray(data),np.asarray(positions)]).tolist())# The result will be:# [[#     [1.0, 3.0, 2.0, 5.0],#     [3.5, 5.0, 4.5, 2.5],#     [4.0, 7.0, 2.0, 5.0],# ]]The default value for argumentpos_typeisPiecewise.POS_TYPE_SEGMENTS, which means splitting the input sequences with increasing positions. Whenpos_typeisPiecewise.POS_TYPE_PAIRS, every two positions represent the piece to be extracted.Piecewise2Dimportkerasimportkeras.backendasKimportnumpyasnpfromkeras_piecewiseimportPiecewise2DclassMaxPool2D(keras.layers.Layer):def__init__(self,**kwargs):super(MaxPool2D,self).__init__(**kwargs)defcall(self,inputs):returnK.max(K.max(inputs,axis=1),axis=1)defcompute_output_shape(self,input_shape):return(input_shape[0],)+input_shape[3:]data=[[[1,3,5,2],[2,5,6,1],[7,1,5,3],[7,2,2,4],],[[1,3,5,2],[2,5,6,1],[7,1,5,3],[7,2,2,4],],]rows=[[2,4],[3,4],]cols=[[1,2,4],[1,3,4],]row_num=len(rows[0])col_num=len(cols[0])data_input=keras.layers.Input(shape=(None,None))row_input=keras.layers.Input(shape=(row_num,))col_input=keras.layers.Input(shape=(col_num,))pool_layer=Piecewise2D(layer=MaxPool2D(),)([data_input,row_input,col_input])model=keras.models.Model(inputs=[data_input,row_input,col_input],outputs=pool_layer)model.compile(optimizer=keras.optimizers.Adam(),loss=keras.losses.mean_squared_error)model.summary()print(model.predict([np.asarray(data),np.asarray(rows),np.asarray(cols)]).tolist())# The result will be:# [#     [#         [2.0, 5.0, 6.0],#         [7.0, 2.0, 5.0],#     ],#     [#         [7.0, 6.0, 3.0],#         [7.0, 2.0, 4.0],#     ],# ]
Package: kerasplugins
# keras-plugins## Callbacks### Telegram CallbackNotify levels available:1) on_train_begin,2) on_train_end,3) on_batch_begin,4) on_batch_end,5) on_epoch_begin,6) on_epoch_end##### How to use##### Installation```pip install kerasplugins``````pythonfrom kerasplugins import callbacks#Notify can either be a list, dict or setnotify = {'on_batch_end',  # sends BATCH END: Loss 0.50 Accuracy: 0.75'on_epoch_end'   # sends EPOCH END: Loss 0.43 Accuracy: 0.81}# msg is the initial messagemsg = "Predicting Bitcoin Price"telegram = callbacks.TelegramNotify(<token>, <chat_id>, msg=msg, notify=notify)# channel is "#general" by defaultslack = callbacks.SlackNotify(<slack_token>, <channel>, msg=msg, notify=notify)model.fit(X_train, Y_train, validation_data=[X_test, Y_test], batch_size=256, epochs=10, callbacks=[telegram, slack])```## Coming Soon1) Ability to stop training remotely