Saravanan666/pypi-org huggingface dataset:
Package: keras-pos-embd
Keras Position Embedding[中文|English]Position embedding layers in Keras.Installpipinstallkeras-pos-embdUsageTrainable Embeddingfromtensorflowimportkerasfromkeras_pos_embdimportPositionEmbeddingmodel=keras.models.Sequential()model.add(PositionEmbedding(input_shape=(None,),input_dim=10,# The maximum absolute value of positions.output_dim=2,# The dimension of embeddings.mask_zero=10000,# The index that presents padding (because `0` will be used in relative positioning).mode=PositionEmbedding.MODE_EXPAND,))model.compile('adam','mse')model.summary()Note that you don't need to enablemask_zeroif you want to add/concatenate other layers like word embeddings with masks:fromtensorflowimportkerasfromkeras_pos_embdimportPositionEmbeddingmodel=keras.models.Sequential()model.add(keras.layers.Embedding(input_shape=(None,),input_dim=10,output_dim=5,mask_zero=True,))model.add(PositionEmbedding(input_dim=100,output_dim=5,mode=PositionEmbedding.MODE_ADD,))model.compile('adam','mse')model.summary()Sin & Cos EmbeddingThesine and cosine embeddinghas no trainable weights. The layer has three modes, it works just likePositionEmbeddinginexpandmode:fromtensorflowimportkerasfromkeras_pos_embdimportTrigPosEmbeddingmodel=keras.models.Sequential()model.add(TrigPosEmbedding(input_shape=(None,),output_dim=30,# The dimension of embeddings.mode=TrigPosEmbedding.MODE_EXPAND,# Use `expand` mode))model.compile('adam','mse')model.summary()If you want to add this embedding to existed embedding, then there is no need to add a position input inaddmode:fromtensorflowimportkerasfromkeras_pos_embdimportTrigPosEmbeddingmodel=keras.models.Sequential()model.add(keras.layers.Embedding(input_shape=(None,),input_dim=10,output_dim=5,mask_zero=True,))model.add(TrigPosEmbedding(output_dim=5,mode=TrigPosEmbedding.MODE_ADD,))model.compile('adam','mse')model.summary()
Package: keras-position-wise-feed-forward
Keras Position-Wise Feed ForwardImplementation of position-wise feed forward layer in the paper:Attention is All You NeedInstallpipinstallkeras-position-wise-feed-forwardUsagefromtensorflowimportkerasfromkeras_position_wise_feed_forwardimportFeedForwardinput_layer=keras.layers.Input(shape=(None,32))feed_forward_layer=FeedForward(units=128)(input_layer)model=keras.models.Model(inputs=input_layer,outputs=feed_forward_layer)model.compile(optimizer='adam',loss='mse')model.summary()
Package: keras-pyramid-pooling-module
Keras Pyramid Pooling ModuleAKerasimplementation of the Pyramid Pooling Module
discussed inPyramid scene parsing network [1].InstallationThe preferred installation ofkeras-pyramid-pooling-moduleis frompip:pipinstallkeras-pyramid-pooling-moduleUsageThe module functions as any other convolutional / pooling layer applied to a
rank 4 tensor (batch, height, width, channels):fromkeras.layersimportInputfromkeras.modelsimportModelfromkeras_pyramid_pooling_moduleimportPyramidPoolingModuleinput_=Input((224,224,3))x=PyramidPoolingModule()(input_)model=Model(inputs=input_,outputs=x)SeePyramidPoolingModule.ipynbfor a rough example
of the layer outputs for a simple RGB image.SeeCIFAR10Classifier.ipynbfor an example of using
the layer in a model to classify images.References[1] H. Zhao, J. Shi, X. Qi, X. Wang, and J. Jia. Pyramid scene parsing network. CVPR, 2017.
Package: keras-quadopt
keras-quadopt: Solving Constrained Quadratic Optimization Problems with Reverse Automatic Differentation (Keras/TF2)Solving quadratic optimization problems with resource constraints and upper boundaries using TF2/Keras.Usageimporttensorflowastfimportkeras_quadoptaskqpimporttime# goodness scoresgood=tf.constant([.51,.53,.55,.57])# similarity matricessimi_1=tf.constant([[1,.9,.8,.7],[.9,1,.6,.5],[.8,.6,1,.4],[.7,.5,.4,1],])simi_2=tf.constant([[1,.7,.8,.3],[.7,1,.4,.2],[.8,.4,1,.6],[.3,.2,.6,1],])# preference parameterslam=0.4beta_1=0.25beta_2=0.75# compute weightssimi=kqp.aggregate_matrices(simi_1,beta_1,simi_2,beta_2)start=time.time()wbest,fbest=kqp.get_weights(good,simi,lam)print(f"elapsed:{time.time()-start}")AppendixInstallationThekeras-quadoptgit repois available asPyPi packagepipinstallkeras-quadopt
pipinstallgit+ssh://git@github.com/ulf1/keras-quadopt.gitInstall a virtual environmentpython3-mvenv.venvsource.venv/bin/activate
pipinstall--upgradepip
pipinstall-rrequirements.txt--no-cache-dir
pipinstall-rrequirements-dev.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 commandsCheck syntax:flake8 --ignore=F401 --exclude=$(grep -v '^#' .gitignore | xargs | sed -e 's/ /,/g')Run Unit Tests:PYTHONPATH=. pytestPublishpythonsetup.pysdisttwineupload-rpypidist/*Clean upfind.-typef-name"*.pyc"|xargsrm
find.-typed-name"__pycache__"|xargsrm-r
rm-r.pytest_cache
rm-r.venvSupportPleaseopen an issuefor support.ContributingPlease contribute usingGithub Flow. Create a branch, add commits, andopen a pull request.AcknowledgementsThe "Evidence" project was funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) -433249742(GU 798/27-1; GE 1119/11-1).Maintenancetill 31.Aug.2023 (v0.1.0) the code repository was maintained within the DFG project433249742since 01.Sep.2023 (v0.2.0) the code repository is maintained by Ulf Hamster.
Package: keras-radam
Keras RAdam[中文|English]Unofficial implementation ofRAdamin Keras and TensorFlow.Installpipinstallkeras-rectified-adamExternal Linktensorflow/addons:RectifiedAdamUsageimportkerasimportnumpyasnpfromkeras_radamimportRAdam# Build toy model with RAdam optimizermodel=keras.models.Sequential()model.add(keras.layers.Dense(input_shape=(17,),units=3))model.compile(RAdam(),loss='mse')# Generate toy datax=np.random.standard_normal((4096*30,17))w=np.random.standard_normal((17,3))y=np.dot(x,w)# Fitmodel.fit(x,y,epochs=5)TensorFlow without Kerasfromkeras_radam.trainingimportRAdamOptimizerRAdamOptimizer(learning_rate=1e-3)Use Warmupfromkeras_radamimportRAdamRAdam(total_steps=10000,warmup_proportion=0.1,min_lr=1e-5)Q & AAbout CorrectnessThe optimizer produces similar losses and weights to the official optimizer after 500 steps.Usetf.kerasortf-2.0AddTF_KERAS=1to environment variables to usetensorflow.python.keras.UsetheanoBackendAddKERAS_BACKEND=theanoto environment variables to enabletheanobackend.
Package: keras-recommenders
Keras RecommendersKeras Recommenders is a library for building recommender system models usingKeras.It was developed with a focus on enabling fast experimentation on recommender system.It's built on Keras and aims to have a gentle learning curve in recommender models.Note:Currently, Keras-recommenders is only support multi task learning framework, more models is preparing!Welcome to join us!InstallationMake sure you have TensorFlow 2.x  andDeepCTRinstalled, and install frompip:pipinstallkeras-recommendersQuick Startfromkeras_recommenders.pleimportPLEmodel=PLE(dnn_feature_columns,num_tasks=2,task_types=['binary','regression'],task_names=['task 1','task 2'],num_levels=2,num_experts_specific=8,num_experts_shared=4,expert_dnn_units=[64,64],gate_dnn_units=[16,16],tower_dnn_units_lists=[[32,32],[32,32]])model.compile("adam",loss=["binary_crossentropy","mean_squared_error"],metrics=['AUC','mae'])model.fit(X_train,[y_task1,y_task2],batch_size=256,epochs=5,verbose=2)y_pred=model.predict(X_test,batch_size=256)Multi-task Learning Models for Recommender SystemsCurrently this project is developed based onDeepCTR:https://github.com/shenweichen/DeepCTR.You can easy to use the code to design your multi task learning model  for multi regression or classification tasks.Example 1Dataset:http://archive.ics.uci.edu/ml/machine-learning-databases/adult/Task 1: (Classification) aims to predict whether the income exceeds 50K.Task 2: (Classification) aims to predict this person’s marital status is never married.Example 2Dataset:https://archive.ics.uci.edu/ml/machine-learning-databases/census-income-mld/PreparingModelDescriptionPaperShared-Bottomshared-bottomMultitask learning(1998)ESMMEntire Space Multi-Task ModelEntire Space Multi-Task Model: An Effective Approach for Estimating Post-Click Conversion Rate(SIGIR'18)MMoEMulti-gate Mixture-of-ExpertsModeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts(KDD'18)CGCCustomized Gate ControlProgressive Layered Extraction (PLE): A Novel Multi-Task Learning (MTL) Model for Personalized Recommendations(RecSys '20)PLEProgressive Layered ExtractionProgressive Layered Extraction (PLE): A Novel Multi-Task Learning (MTL) Model for Personalized Recommendations(RecSys '20)Shared-Bottom & MMOEESMMCGCPLE
Package: keras-rectified-adam
Keras RAdam[中文|English]Unofficial implementation ofRAdamin Keras.Installpipinstallkeras-rectified-adamExternal Linktensorflow/addons:RectifiedAdamUsagefromtensorflowimportkerasimportnumpyasnpfromkeras_radamimportRAdam# Build toy model with RAdam optimizermodel=keras.models.Sequential()model.add(keras.layers.Dense(input_shape=(17,),units=3))model.compile(RAdam(),loss='mse')# Generate toy datax=np.random.standard_normal((4096*30,17))w=np.random.standard_normal((17,3))y=np.dot(x,w)# Fitmodel.fit(x,y,epochs=5)Use Warmupfromkeras_radamimportRAdamRAdam(total_steps=10000,warmup_proportion=0.1,min_lr=1e-5)
Package: keras-rnadam
Keras RNAdamuse of nesterov accelerated geadient instead of momentum in rectified-adamInstallpipinstallkeras_rnadamUsageimportkerasimportnumpyasnpfromkeras_rnadamimportRNAdam# Build toy model with RNAdam optimizermodel=keras.models.Sequential()model.add(keras.layers.Dense(input_shape=(17,),units=3))model.compile(RNAdam(),loss='mse')# Generate toy datax=np.random.standard_normal((4096*30,17))w=np.random.standard_normal((17,3))y=np.dot(x,w)# Fitmodel.fit(x,y,epochs=5)Use Warmupfromkeras_nradamimportRNAdamRNAdam(total_step=10000,warmup_proportion=0.1,min_lr=1e-5)
Package: keras-secure-image
This package is an add on library on top of keras or tensorflow.
The aim of this package is to provide privacy of images by enabling the model to be trained on encrypted images.Read the documentation at:https://github.com/akshaybahadur21/keras-secure-imageFor a detailed code overview on colab, see:https://colab.research.google.com/drive/1D7ziODKrzL0QK-GuI7BH9f9Fk7U3tfUWkeras-secure-image is compatible with Python 2.7-3.6
and is distributed under the MIT license.
Package: keras-self-attention
Keras Self-Attention[中文|English]Attention mechanism for processing sequential data that considers the context for each timestamp.Installpipinstallkeras-self-attentionUsageBasicBy default, the attention layer uses additive attention and considers the whole context while calculating the relevance. The following code creates an attention layer that follows the equations in the first section (attention_activationis the activation function ofe_{t, t'}):importkerasfromkeras_self_attentionimportSeqSelfAttentionmodel=keras.models.Sequential()model.add(keras.layers.Embedding(input_dim=10000,output_dim=300,mask_zero=True))model.add(keras.layers.Bidirectional(keras.layers.LSTM(units=128,return_sequences=True)))model.add(SeqSelfAttention(attention_activation='sigmoid'))model.add(keras.layers.Dense(units=5))model.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['categorical_accuracy'],)model.summary()Local AttentionThe global context may be too broad for one piece of data. The parameterattention_widthcontrols the width of the local context:fromkeras_self_attentionimportSeqSelfAttentionSeqSelfAttention(attention_width=15,attention_activation='sigmoid',name='Attention',)Multiplicative AttentionYou can use multiplicative attention by settingattention_type:fromkeras_self_attentionimportSeqSelfAttentionSeqSelfAttention(attention_width=15,attention_type=SeqSelfAttention.ATTENTION_TYPE_MUL,attention_activation=None,kernel_regularizer=keras.regularizers.l2(1e-6),use_attention_bias=False,name='Attention',)RegularizerTo use the regularizer, setattention_regularizer_weightto a positive number:importkerasfromkeras_self_attentionimportSeqSelfAttentioninputs=keras.layers.Input(shape=(None,))embd=keras.layers.Embedding(input_dim=32,output_dim=16,mask_zero=True)(inputs)lstm=keras.layers.Bidirectional(keras.layers.LSTM(units=16,return_sequences=True))(embd)att=SeqSelfAttention(attention_type=SeqSelfAttention.ATTENTION_TYPE_MUL,kernel_regularizer=keras.regularizers.l2(1e-4),bias_regularizer=keras.regularizers.l1(1e-4),attention_regularizer_weight=1e-4,name='Attention')(lstm)dense=keras.layers.Dense(units=5,name='Dense')(att)model=keras.models.Model(inputs=inputs,outputs=[dense])model.compile(optimizer='adam',loss={'Dense':'sparse_categorical_crossentropy'},metrics={'Dense':'categorical_accuracy'},)model.summary(line_length=100)Load the ModelMake sure to addSeqSelfAttentionto custom objects:importkeraskeras.models.load_model(model_path,custom_objects=SeqSelfAttention.get_custom_objects())History OnlySethistory_onlytoTruewhen only historical data could be used:SeqSelfAttention(attention_width=3,history_only=True,name='Attention',)Multi-HeadPlease refer tokeras-multi-head.
Package: keras-succ-reg-wrapper
Keras Successive Regularization WrapperA wrapper that slows down the updates of trainable weights.Installpipinstallkeras-succ-reg-wrapperUsageimportkerasfromkeras_succ_reg_wrapperimportSuccReginput_layer=keras.layers.Input(shape=(1,),name='Input')dense_layer=SuccReg(layer=keras.layers.Dense(units=1,name='Dense'),regularizer=keras.regularizers.L1L2(l2=1e-3),# Any regularizername='Output',)(input_layer)model=keras.models.Model(inputs=input_layer,outputs=dense_layer)model.compile(optimizer='adam',loss='mse')model.summary()
Package: keras-synthetic-genome-sequence
Python package to lazily generate synthetic genomic sequences for training of Keras models.How do I install this package?As usual, just download it using pip:pipinstallkeras_synthetic_genome_sequenceTests CoverageSince some software handling coverages sometime
get slightly different results, here’s three of them:Usage examplesTo use GapSequence to train your keras model you
will need to obtain statistical metrics for the
biological gaps you intend to mimic in your synthetic gaps.To achieve this, this package offers an utility called
get_gaps_statistics, which allows you to obtain the
mean and covariance of gaps in a given genomic assembly.The genomic assembly is automatically downloaded from UCSC
usingucsc_genomes_downloader,
then the gaps contained within are extracted and their windows
is expanded to the given one, after filtering for the given
max_gap_size, as you might want to limit the gaps size to
a relatively small one (gaps can get in the tens of thousands
of nucleotides, for instance in the telomeres).Let’s start by listing all the important parameters:assembly="hg19"window_size=200batch_size=128Now we can start by retrieving the gaps statistics:fromkeras_synthetic_genome_sequence.utilsimportget_gaps_statisticsnumber,mean,covariance=get_gaps_statistics(assembly=assembly,max_gap_size=100,window_size=window_size)print("I have identified{number}gaps!".format(number=number))Now you must choose the ground truth on which to apply the
synthetic gaps, for instance the regions without gaps in
the genomic assembly hg19, chromosome chr1.
These regions will have to be tasselized into smaller
chunks that are compatible with the shape you have chosen for
the gap statistics window_size.
We can retrieve these regions as follows:fromucsc_genomes_downloaderimportGenomefromucsc_genomes_downloader.utilsimporttessellate_bedgenome=Genome(assembly,chromosomes=["chr1"])ground_truth=tessellate_bed(genome.filled(),window_size=window_size)The obtained pandas DataFrame will have a bed-like format
and look as follows:chromchromStartchromEnd0chr110000102001chr110200104002chr110400106003chr110600108004chr11080011000Now we are ready to actually create the GapSequence:fromkeras_synthetic_genome_sequenceimportGapSequencegap_sequence=GapSequence(assembly=assembly,bed=ground_truth,gaps_mean=mean,gaps_covariance=covariance,batch_size=batch_size)Now, having a model that receives as
input and output shape (batch_size, window_size, 4),
we can train it as follows:model=build_my_denoiser()model.fit_generator(gap_sequence,steps_per_epoch=gap_sequence.steps_per_epoch,epochs=2,shuffle=True)Happy denoising!Comparison between biological and synthetic distributionsThe following images refer to the biological and synthetic distributions
of gaps in the hg19, hg38, mm9 and mm10 genomic assembly, considering
gaps with length to up 100 nucleotides and total window size 1000.
The threshold used to convert to integer the multivariate gaussian distribution
is 0.4, the default value used within the python package.
Package: keras-targeted-dropout
Keras Targeted DropoutUnofficial implementation ofTargeted Dropoutwith tensorflow backend.
Note that there is no model compression in this implementation.Installpipinstallkeras-targeted-dropoutUsageimportkerasfromkeras_targeted_dropoutimportTargetedDropoutmodel=keras.models.Sequential()model.add(TargetedDropout(layer=keras.layers.Dense(units=2,activation='softmax'),drop_rate=0.8,target_rate=0.2,drop_patterns=['kernel'],mode=TargetedDropout.MODE_UNIT,input_shape=(5,),))model.compile(optimizer='adam',loss='mse')model.summary()drop_rate: Dropout rate for each pixel.target_rate: The proportion of bottom weights selected as candidatesdrop_patterns: A list of names of weights to be dropped.mode:TargetedDropout.MODE_UNITorTargetedDropout.MODE_WEIGHT.The final dropout rate will bedrop_ratetimestarget_rate.
Package: keras-toolbox
# keras-toolbox[![PyPI version](https://img.shields.io/pypi/v/keras-toolbox.svg?maxAge=2591000)](https://pypi.org/project/keras-toolbox/)
[![License ](https://img.shields.io/pypi/l/keras-toolbox.svg?maxAge=2591000)](LICENSE)Your every day Keras toolbox.The spirit of this library is to add some features missing from Keras and that make your workflow more smooth and easier. If these features start to be widely used it could be a good idea to propose them as a PR in the Keras repo.Current features are :`Monitor` callbacksto easily get information about your model training. Current callbacks allow to write the state in a file as a JSON or to send the state to a Telegram user ID.Visualization functions: some functions to easily visualize weights and feature maps form a specific layer or all the layers.Augmentation functions: trying to replace the Keras augmentation API but the code is very crappy at the moment.## DependenciesPython 3 only (it’s time to move)the classicsnumpy,pandas,scipyKerasmatplotlibfor the visualizationpython-telegram-botfor theTelegramMonitorcallback## DocumentationThe project is not big enough to write a proper doc for now. See this [Notebook](doc/example.ipynb) for a short documentation.## AuthorHadrien Mary <hadrien.mary@gmail.com>## LicenseMIT license. See [LICENSE](LICENSE).
Package: keras-toolkit
Keras ToolkitA collection of functions to help you easily train and run Tensorflow KerasGet the completeAPI reference here.QuickstartInstall the library:pip install keras-toolkitYou can now use it:importkeras_toolkitaskt# kt reduces the number of lines from ~100 to ~3strategy=kt.accelerator.auto_select(verbose=True)decoder=kt.image.build_decoder(with_labels=True,target_size=(300,300))dtrain=kt.image.build_dataset(paths,labels,bsize=BATCH_SIZE,decode_fn=decoder)withstrategy.scope():model=tf.keras.Sequential([...])model.compile(...)model.fit(...)UsageTo automatically select an accelerator (e.g. TPU, GPU, CPU) and run on that accelerator:importkeras_toolkitasktstrategy=kt.accelerator.auto_select(verbose=True)withstrategy.scope():# your keras code heremodel=tf.keras.Sequential([...])To restrict the GPU memory usage of TensorFlow (e.g. to 2GB):importkeras_toolkitasktkt.accelerator.limit_gpu_memory(2*1024)To build an image dataset from a list of paths and a list of labels (associated with the paths):importkeras_toolkitasktdtrain=kt.image.build_dataset(paths,labels)# => <PrefetchDataset shapes: ((None, 256, 256, 3), (None,)), types: (tf.float32, tf.int32)># Fit your keras model on that new tf.data.Dataset:model.fit(dtrain,...)If you only have a list of image paths, it will createtf.data.Datasetwithout labels:dtrain=kt.image.build_dataset(paths)# => <PrefetchDataset shapes: (None, 256, 256, 3), types: tf.float32>You can also customize the dataset (e.g. batch size, custom image loader, custom augmentation, etc.):# This is just the defaultimg_decoder=kt.image.build_decoder(target_size=(512,512))augmenter=kt.image.build_augmenter()dset=build_dataset(paths,labels,decode_fn=img_decoder,bsize=64,cache="./cache_dir/",augment=augmenter,shuffle=False,random_state=42)AcknowledgementThekt.accelerator.auto_select_acceleratorwas inspired byMartin Gorner's Kaggle notebook.Thekt.accelerator.limit_gpu_memorywas taken fromChris Deotte's Kaggle notebook.
Package: kerastorch
kerastorch 是一个通用的pytorch模型训练模版工具，你可以像使用keras一样，使用pytorch,它具有如下优点：好看(代码优雅，日志美丽，自带可视化)好用(使用方便，支持 进度条、评估指标、early-stopping等常用功能，支持tensorboard，wandb回调函数等扩展功能)好改(修改简单，核心代码模块化，仅约200行，并提供丰富的修改使用案例)使用方法 🍊🍊安装 kerastorchpip install kerastorch通过使用kerastorch，你不需要写自己的pytorch模型训练循环。你只要做这样两步就可以了。(1) 创建你的模型结构net,然后把它和损失函数传入kerastorch.KerasModel构建一个model。(2) 使用model的fit方法在你的训练数据和验证数据上进行训练，训练数据和验证数据需要封装成两个DataLoader.核心使用代码就像下面这样：importtorchimportkerastorchimporttorchmetricsmodel=kerastorch.KerasModel(net,loss_fn=nn.BCEWithLogitsLoss(),optimizer=torch.optim.Adam(net.parameters(),lr=1e-4),metrics_dict={"acc":torchmetrics.Accuracy(task='binary')})dfhistory=model.fit(train_data=dl_train,val_data=dl_val,epochs=20,patience=3,ckpt_path='checkpoint.pt',monitor="val_acc",mode="max",plot=True,)在jupyter notebook中执行训练代码，你将看到类似下面的训练可视化图像和训练日志进度条。主要特性 🍉🍉kerastorch 支持以下这些功能特性，稳定支持这些功能的起始版本以及这些功能借鉴或者依赖的库的来源见下表。功能稳定支持起始版本依赖或借鉴库✅ 训练进度条3.0.0依赖tqdm,借鉴keras✅ 训练评估指标3.0.0借鉴pytorch_lightning✅ notebook中训练自带可视化3.8.0借鉴fastai✅ early stopping3.0.0借鉴keras✅ gpu training3.0.0依赖accelerate✅ multi-gpus training(ddp)3.6.0依赖accelerate✅ fp16/bf16 training3.6.0依赖accelerate✅ tensorboard callback3.7.0依赖tensorboard✅ wandb callback3.7.0依赖wandb