├── .clang-format ├── .github └── workflows │ └── py.yml ├── .gitignore ├── Audio ├── AM-MobileNet1D │ ├── README.md │ ├── cfg │ │ ├── AM_MobileNet1D_TIMIT.cfg │ │ └── MobileNet1D_TIMIT.cfg │ ├── infer.py │ ├── infer.sh │ ├── model │ │ └── mobilenet1d.py │ ├── requirements.txt │ ├── train.py │ ├── train.sh │ └── utils │ │ ├── TIMIT_preparation.py │ │ └── data_utils.py ├── Adaptive_Voice_Conversion │ ├── README.md │ ├── config.yaml │ ├── data_utils.py │ ├── infer.sh │ ├── inference.py │ ├── main.py │ ├── model.py │ ├── preprocess │ │ ├── make_datasets_vctk.py │ │ ├── preprocess_vctk.sh │ │ ├── reduce_dataset.py │ │ ├── sample_segments.py │ │ ├── sample_single_segments.py │ │ ├── tacotron │ │ │ ├── hyperparams.py │ │ │ └── utils.py │ │ └── vctk.config │ ├── solver.py │ ├── train.sh │ └── utils.py ├── Conv-TasNet │ ├── .gitattributes │ ├── .gitignore │ ├── README.md │ ├── conv_tasnet_loss.png │ ├── nnet │ │ ├── compute_si_snr.py │ │ ├── conv_tas_net.py │ │ ├── create_scp.py │ │ ├── libs │ │ │ ├── __init__.py │ │ │ ├── audio.py │ │ │ ├── dataset.py │ │ │ ├── metric.py │ │ │ ├── trainer.py │ │ │ └── utils.py │ │ ├── separate.py │ │ └── train.py │ ├── requirements.txt │ └── run.sh ├── CycleGAN-VC2 │ ├── README.md │ ├── infer.py │ ├── infer.sh │ ├── model │ │ ├── model.py │ │ └── trainr.py │ ├── requirements.txt │ ├── train.py │ ├── train.sh │ └── utils │ │ ├── data_preprocess.py │ │ ├── data_utils.py │ │ └── dataset.py ├── MaskCycleGAN-VC │ ├── README.md │ ├── args │ │ └── cycleGAN_arg_parser.py │ ├── infer.py │ ├── infer.sh │ ├── model │ │ ├── model.py │ │ └── trainer.py │ ├── requirements.txt │ ├── train.py │ ├── train.sh │ └── utils │ │ ├── data_preprocess.py │ │ ├── data_utils.py │ │ └── dataset.py ├── OpenTransformer │ ├── README.md │ ├── average.sh │ ├── egs │ │ └── aishell │ │ │ ├── conf │ │ │ ├── conformer_baseline.yaml │ │ │ ├── rnnlm.yaml │ │ │ ├── transformer_baseline.yaml │ │ │ └── transformer_lm.yaml │ │ │ ├── local │ │ │ ├── aishell_data_prep.sh │ │ │ ├── download_and_untar.sh │ │ │ ├── filter_scp.pl │ │ │ ├── generate_vocab.py │ │ │ ├── prepare_data.py │ │ │ └── split_and_norm.py │ │ │ ├── path.sh │ │ │ └── run.sh │ ├── eval.py │ ├── eval.sh │ ├── otrans │ │ ├── __init__.py │ │ ├── decoder │ │ │ ├── __init__.py │ │ │ ├── base.py │ │ │ ├── transformer.py │ │ │ └── utils.py │ │ ├── encoder │ │ │ ├── __init__.py │ │ │ ├── base.py │ │ │ ├── conformer.py │ │ │ ├── transformer.py │ │ │ └── utils.py │ │ ├── frontend │ │ │ ├── __init__.py │ │ │ ├── base.py │ │ │ ├── concat.py │ │ │ └── conv.py │ │ ├── model │ │ │ ├── __init__.py │ │ │ ├── base.py │ │ │ ├── ctc.py │ │ │ ├── lm.py │ │ │ └── speech2text.py │ │ ├── module │ │ │ ├── __init__.py │ │ │ ├── attention.py │ │ │ ├── conformer.py │ │ │ ├── ffn.py │ │ │ ├── loss.py │ │ │ └── pos.py │ │ ├── recognize │ │ │ ├── __init__.py │ │ │ ├── base.py │ │ │ ├── ctc.py │ │ │ ├── speech2text.py │ │ │ └── utils.py │ │ ├── train │ │ │ ├── __init__.py │ │ │ ├── scheduler.py │ │ │ ├── trainer.py │ │ │ └── utils.py │ │ └── utils.py │ ├── run.py │ ├── tools │ │ ├── average.py │ │ └── computer_wer.py │ └── train.sh ├── SincNet │ ├── README.md │ ├── cfg │ │ └── SincNet_TIMIT.cfg │ ├── infer.py │ ├── infer.sh │ ├── model │ │ ├── SincNet.py │ │ └── dnn_models.py │ ├── train.py │ ├── train.sh │ └── utils │ │ ├── TIMIT_preparation.py │ │ └── data_utils.py ├── Speech-Emotion-Analyzer │ ├── .editorconfig │ ├── .gitattributes │ ├── .gitignore │ ├── README.md │ ├── configs │ │ ├── cnn1d.yaml │ │ └── lstm.yaml │ ├── extract_feats │ │ ├── librosa.py │ │ └── opensmile.py │ ├── models │ │ ├── __init__.py │ │ ├── cnn1d_ser.py │ │ ├── lstm_oneflow.py │ │ └── lstm_ser.py │ ├── predict.py │ ├── predict.sh │ ├── preprocess.py │ ├── requirements.txt │ ├── train.py │ ├── train.sh │ └── utils │ │ ├── __init__.py │ │ ├── opts.py │ │ └── plot.py ├── Speech-Transformer │ ├── .gitignore │ ├── README.md │ ├── egs │ │ └── aishell │ │ │ ├── cmd.sh │ │ │ ├── conf │ │ │ └── fbank.conf │ │ │ ├── figures │ │ │ └── tr_val_loss_15000bf.png │ │ │ ├── local │ │ │ ├── aishell_data_prep.sh │ │ │ └── score.sh │ │ │ ├── loss_visualize.py │ │ │ ├── path.sh │ │ │ ├── run.sh │ │ │ ├── steps │ │ │ └── utils │ ├── src │ │ ├── __init__.py │ │ ├── bin │ │ │ ├── recognize.py │ │ │ └── train.py │ │ ├── data │ │ │ ├── __init__.py │ │ │ └── data.py │ │ ├── solver │ │ │ ├── __init__.py │ │ │ └── solver.py │ │ ├── transformer │ │ │ ├── __init__.py │ │ │ ├── attention.py │ │ │ ├── decoder.py │ │ │ ├── encoder.py │ │ │ ├── loss.py │ │ │ ├── module.py │ │ │ ├── optimizer.py │ │ │ └── transformer.py │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── data2json.sh │ │ │ ├── dump.sh │ │ │ ├── filt.py │ │ │ ├── json2trn.py │ │ │ ├── mergejson.py │ │ │ ├── scp2json.py │ │ │ ├── text2token.py │ │ │ └── utils.py │ └── tools │ │ ├── Makefile │ │ └── kaldi-io-for-python.tar.gz ├── StarGAN-VC │ ├── README.md │ ├── infer.sh │ ├── main.py │ ├── model │ │ ├── data_loader.py │ │ ├── model.py │ │ └── solver.py │ ├── requirements.txt │ ├── train.sh │ └── utils │ │ ├── preprocess.py │ │ └── utility.py └── Wav2Letter │ ├── README.md │ ├── Wav2Letter │ ├── data.py │ ├── decoder.py │ └── model.py │ ├── infer.py │ ├── infer.sh │ ├── requirements.txt │ ├── train.py │ └── train.sh ├── CMakeLists.txt ├── DeepReinforcementLearning ├── FlappyBird │ ├── README.md │ ├── assets │ │ └── sprites │ │ │ ├── 0.png │ │ │ ├── 1.png │ │ │ ├── 2.png │ │ │ ├── 3.png │ │ │ ├── 4.png │ │ │ ├── 5.png │ │ │ ├── 6.png │ │ │ ├── 7.png │ │ │ ├── 8.png │ │ │ ├── 9.png │ │ │ ├── background-black.png │ │ │ ├── base.png │ │ │ ├── pipe-green.png │ │ │ ├── redbird-downflap.png │ │ │ ├── redbird-midflap.png │ │ │ └── redbird-upflap.png │ ├── game │ │ ├── flappy_bird_utils.py │ │ └── wrapped_flappy_bird.py │ ├── model │ │ ├── deep_q_network.py │ │ └── utils.py │ ├── requirements.txt │ ├── test.py │ ├── test_flappy_bird.sh │ ├── train.py │ └── train_flappy_bird.sh └── MadMario │ ├── README.md │ ├── agent.py │ ├── environment.yml │ ├── main.py │ ├── metrics.py │ ├── neural.py │ ├── replay.py │ └── wrappers.py ├── Demo ├── quick_start_demo_lenet │ └── lenet.py └── speaker_identification_demo │ ├── README.md │ ├── data_preprocess.py │ ├── data_preprocess.sh │ ├── infer.py │ ├── infer.sh │ ├── model │ ├── dataloader.py │ └── model.py │ ├── train.py │ └── train.sh ├── GPT ├── examples │ ├── 2d_parallel_train.sh │ ├── pipeline_train.sh │ ├── train_117M.sh │ ├── train_2x2x2_12x1536_512x1024.sh │ └── train_2x4x4_24x2304_512x2048.sh ├── oneflow_gpt │ ├── __init__.py │ ├── config.py │ ├── data.py │ ├── distribute.py │ ├── logger.py │ ├── model.py │ ├── optimizer.py │ └── train.py └── setup.py ├── KnowledgeDistillation ├── KnowledgeDistillation │ ├── README.md │ ├── infer.py │ ├── infer.sh │ ├── model.py │ ├── requirements.txt │ ├── train.py │ └── train.sh └── MetaKD │ ├── 1_get_data.sh │ ├── 2_process_data.sh │ ├── 3_train_teacher.sh │ ├── 4_student_first.sh │ ├── 5_student_second.sh │ ├── 6_eval.sh │ ├── README.md │ ├── bert.py │ ├── bert_utils.py │ ├── easynlp │ ├── appzoo │ │ ├── __init__.py │ │ ├── api.py │ │ ├── application.py │ │ ├── dataset.py │ │ └── sequence_classification │ │ │ ├── __init__.py │ │ │ └── evaluator.py │ ├── core │ │ ├── __init__.py │ │ ├── distiller.py │ │ ├── evaluator.py │ │ ├── optimizers.py │ │ └── trainer.py │ ├── distillation │ │ ├── __init__.py │ │ ├── distill_application.py │ │ ├── distill_metakd_application.py │ │ └── distill_metakd_dataset.py │ ├── modelzoo │ │ ├── __init__.py │ │ ├── configuration_utils.py │ │ ├── file_utils.py │ │ ├── models │ │ │ ├── auto │ │ │ │ ├── __init__.py │ │ │ │ ├── configuration_auto.py │ │ │ │ └── tokenization_auto.py │ │ │ └── bert │ │ │ │ ├── __init__.py │ │ │ │ ├── configuration_bert.py │ │ │ │ ├── tokenization_bert.py │ │ │ │ └── tokenization_bert_fast.py │ │ ├── tokenization_utils.py │ │ ├── tokenization_utils_base.py │ │ ├── tokenization_utils_fast.py │ │ └── utils │ │ │ ├── __init__.py │ │ │ └── logging.py │ ├── requirements.txt │ └── utils │ │ ├── __init__.py │ │ ├── arguments.py │ │ ├── exporter.py │ │ ├── global_vars.py │ │ ├── initializer.py │ │ ├── io_utils.py │ │ ├── logger.py │ │ ├── losses.py │ │ └── statistics.py │ ├── extract_embeddings.py │ ├── generate_dev_file.py │ ├── generate_meta_weights.py │ ├── generate_senti_data.py │ ├── main_evaluate.py │ ├── meta_student_distill.py │ ├── meta_teacher_train.py │ └── requirements.txt ├── LICENSE ├── NLP ├── BERT │ ├── README.md │ ├── config.py │ ├── examples │ │ ├── infer.sh │ │ ├── run_eager_pretrain.sh │ │ ├── run_graph_pretrain.sh │ │ └── run_squad.sh │ ├── modeling.py │ ├── run_eager_pretraining.py │ ├── run_infer.py │ ├── run_pretraining.py │ ├── run_squad.py │ ├── squad.py │ ├── squad_util.py │ ├── tokenization.py │ └── utils │ │ ├── checkpoint.py │ │ ├── comm.py │ │ ├── compare_lazy_outputs.py │ │ ├── draw_img.py │ │ ├── draw_loss_curve.py │ │ ├── lamb_optimizer.py │ │ ├── lr_scheduler.py │ │ ├── metric.py │ │ ├── ofrecord_data_utils.py │ │ ├── optimizer.py │ │ └── reporter.py ├── CPT │ ├── README.md │ ├── classifier_flow.py │ ├── dataset_flow.py │ ├── infer.sh │ ├── infer_flow.py │ ├── models │ │ ├── CPT.py │ │ ├── bart_utils.py │ │ ├── bert.py │ │ ├── bert_utils.py │ │ └── utils.py │ ├── requirements.txt │ ├── train.sh │ └── train_flow.py ├── GPT2 │ ├── README.md │ ├── compare_speed.py │ ├── config.py │ ├── convert_pt_ckpt_to_of.py │ ├── finetune.sh │ ├── generate_sample.py │ ├── gpt_dataset.py │ ├── gpt_dataset_pt.py │ ├── infer.sh │ ├── model.py │ ├── model_config.py │ ├── optimization.py │ ├── optimization_pt.py │ ├── pt_model.py │ ├── requirements.txt │ ├── run_generation.py │ ├── tokenizer │ │ ├── __init__.py │ │ ├── gpt2_tokenization.py │ │ └── tokenizer.py │ ├── train.py │ ├── train.sh │ ├── train_pt.py │ ├── trainer.py │ └── trainer_pt.py ├── LSTMText │ ├── README.md │ ├── infer.py │ ├── infer.sh │ ├── model.py │ ├── requirements.txt │ ├── train.sh │ ├── train_bilstm.py │ └── utils.py ├── MoE │ ├── README.md │ ├── cifar10_example.py │ ├── mlp.py │ ├── moe.py │ ├── requirements.txt │ └── train.sh ├── TextCNN │ ├── README.md │ ├── infer.py │ ├── infer.sh │ ├── model.py │ ├── requirements.txt │ ├── train.sh │ ├── train_of_textcnn.py │ ├── training.py │ └── utils.py ├── Transformer │ ├── README.md │ ├── imdb │ │ ├── infer.sh │ │ ├── infer_transformer_imdb.py │ │ ├── model.py │ │ ├── train.sh │ │ ├── train_transformer_imdb.py │ │ └── utils.py │ ├── odd_numbers │ │ ├── infer.sh │ │ ├── infer_transformer_odd_numbers.py │ │ ├── model.py │ │ ├── train.sh │ │ └── train_transformer_odd_numbers.py │ └── transformer │ │ ├── __init__.py │ │ ├── multihead_attention.py │ │ ├── transformer.py │ │ └── utils.py ├── rnn │ ├── README.md │ ├── compare_oneflow_and_pytorch_lstm_speed.py │ ├── compare_oneflow_and_pytorch_rnn_speed.py │ ├── models │ │ ├── __init__.py │ │ ├── lstm_oneflow.py │ │ ├── lstm_pytorch.py │ │ ├── rnn_model.py │ │ └── rnn_model_pytorch.py │ ├── predict.py │ ├── requirements.txt │ ├── train.sh │ ├── train_lstm_oneflow.py │ ├── train_rnn_oneflow.py │ └── utils │ │ ├── __init__.py │ │ ├── dataset.py │ │ └── tensor_utils.py ├── roberta │ ├── MNLIDataset.py │ ├── README.md │ ├── SST2Dataset.py │ ├── classifier_MNLI.py │ ├── classifier_SST2.py │ ├── config.py │ ├── infer_MNLI.py │ ├── infer_MNLI.sh │ ├── infer_SST2.py │ ├── infer_SST2.sh │ ├── models │ │ ├── roberta.py │ │ └── roberta_utils.py │ ├── requirements.txt │ ├── train_MNLI.py │ ├── train_MNLI.sh │ ├── train_SST2.py │ └── train_SST2.sh └── seq2seq │ ├── README.md │ ├── eval_oneflow.py │ ├── eval_oneflow.sh │ ├── models │ ├── GRU_oneflow.py │ ├── __init__.py │ └── seq_seq_oneflow.py │ ├── requirements.txt │ ├── train_oneflow.py │ ├── train_oneflow.sh │ └── utils │ ├── __init__.py │ ├── dataset.py │ └── utils_oneflow.py ├── Quantization ├── README.md ├── __init__.py ├── infer.sh ├── models │ └── q_alexnet.py ├── quantization_aware_training.py ├── quantization_infer.py ├── quantization_ops │ ├── __init__.py │ ├── conv.py │ ├── conv_bn.py │ ├── linear.py │ └── q_module.py ├── train.sh └── utils │ ├── __init__.py │ ├── imagenet1000_clsidx_to_labels.py │ ├── numpy_data_utils.py │ ├── ofrecord_data_utils.py │ └── plot.py ├── README.md ├── README_zh-CN.md ├── RecommenderSystems ├── dcn │ ├── README.md │ ├── dcn_eager_train_eval.py │ ├── dcn_train_eval.py │ ├── eager_train.sh │ ├── requirements.txt │ ├── tools │ │ ├── dcn_parquet.scala │ │ ├── launch_spark.sh │ │ └── split_criteo.py │ └── train.sh ├── deepfm │ ├── README.md │ ├── deepfm_eager_train_eval.py │ ├── deepfm_train_eval.py │ ├── eager_train.sh │ ├── tools │ │ ├── deepfm_parquet.scala │ │ ├── launch_spark.sh │ │ └── split_criteo_kaggle.py │ └── train_deepfm.sh ├── dlrm │ ├── README.md │ ├── __init__.py │ ├── dlrm_train_eval.py │ ├── requirements.txt │ └── tools │ │ ├── criteo1t_parquet.py │ │ ├── criteo1t_parquet.scala │ │ ├── criteo1t_parquet_day_by_day.scala │ │ ├── launch_spark.sh │ │ └── split_day_23.sh ├── mmoe │ ├── README.md │ ├── mmoe_train_eval.py │ ├── tools │ │ └── mmoe_parquet.py │ └── train_mmoe.sh ├── pnn │ ├── README.md │ ├── pnn_train_eval.py │ ├── tools │ │ ├── criteo_parquet.py │ │ ├── launch_spark.sh │ │ └── split_criteo_kaggle.py │ └── train_pnn.sh ├── wide_and_deep │ ├── README.md │ ├── __init__.py │ ├── config.py │ ├── graph.py │ ├── models │ │ ├── __init__.py │ │ ├── data.py │ │ └── wide_and_deep.py │ ├── train.py │ ├── train_ddp.sh │ ├── train_global_eager.sh │ ├── train_global_graph.sh │ ├── train_nn_graph.sh │ └── utils │ │ └── logger.py └── xdeepfm │ ├── README.md │ ├── tools │ ├── launch_spark.sh │ ├── split_criteo_kaggle.py │ └── xdeepfm_parquet.scala │ ├── train_xdeepfm.sh │ └── xdeepfm_train_eval.py ├── Vision ├── BJTU_summer_tournament │ ├── DataSet.py │ ├── DenseNet.py │ ├── Predict.py │ ├── Prepare.py │ ├── README.md │ ├── Train.py │ └── requirements.txt ├── LSTM │ └── EnResLSTM │ │ ├── README.md │ │ ├── infer.py │ │ ├── run.sh │ │ └── train.py ├── classification │ ├── image │ │ ├── DLA │ │ │ ├── README.md │ │ │ ├── infer.py │ │ │ ├── infer.sh │ │ │ ├── models │ │ │ │ └── dla.py │ │ │ ├── requirements.txt │ │ │ ├── train_oneflow.py │ │ │ ├── train_oneflow.sh │ │ │ └── utils │ │ │ │ ├── clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ └── ofrecord_data_utils.py │ │ ├── ViT │ │ │ ├── README.md │ │ │ ├── eager │ │ │ │ ├── infer.py │ │ │ │ ├── infer.sh │ │ │ │ ├── train.py │ │ │ │ └── train.sh │ │ │ ├── graph │ │ │ │ ├── infer.py │ │ │ │ ├── infer.sh │ │ │ │ ├── train.py │ │ │ │ └── train.sh │ │ │ ├── model │ │ │ │ ├── __init__.py │ │ │ │ ├── build_model.py │ │ │ │ └── vit.py │ │ │ ├── requirements.txt │ │ │ └── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ └── ofrecord_data_utils.py │ │ ├── alexnet │ │ │ ├── README.md │ │ │ ├── check │ │ │ │ ├── check.py │ │ │ │ ├── check.sh │ │ │ │ ├── draw.py │ │ │ │ └── draw.sh │ │ │ ├── eager │ │ │ │ ├── infer.py │ │ │ │ ├── infer.sh │ │ │ │ ├── train.py │ │ │ │ └── train.sh │ │ │ ├── graph │ │ │ │ ├── infer.py │ │ │ │ ├── infer.sh │ │ │ │ ├── train.py │ │ │ │ └── train.sh │ │ │ ├── model │ │ │ │ ├── __init__.py │ │ │ │ └── alexnet.py │ │ │ ├── requirements.txt │ │ │ └── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ ├── ofrecord_data_utils.py │ │ │ │ └── plot.py │ │ ├── densenet │ │ │ ├── README.md │ │ │ ├── infer.py │ │ │ ├── infer.sh │ │ │ ├── models │ │ │ │ ├── __init__.py │ │ │ │ └── densenet.py │ │ │ ├── requirements.txt │ │ │ ├── train.py │ │ │ ├── train.sh │ │ │ └── utils │ │ │ │ ├── Figure_1.png │ │ │ │ ├── __init__.py │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ ├── ofrecord_data_utils.py │ │ │ │ └── plot.py │ │ ├── ghostnet │ │ │ ├── README.md │ │ │ ├── infer.py │ │ │ ├── infer.sh │ │ │ ├── models │ │ │ │ └── ghostnet.py │ │ │ ├── train_oneflow.py │ │ │ ├── train_oneflow.sh │ │ │ └── utils │ │ │ │ ├── ghostnet_compare.png │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ └── ofrecord_data_utils.py │ │ ├── inception_v3 │ │ │ ├── README.md │ │ │ ├── eager │ │ │ │ ├── infer.py │ │ │ │ ├── infer.sh │ │ │ │ ├── train.py │ │ │ │ └── train.sh │ │ │ ├── graph │ │ │ │ ├── build_graph.py │ │ │ │ ├── config.py │ │ │ │ ├── data.py │ │ │ │ ├── infer.py │ │ │ │ ├── infer.sh │ │ │ │ ├── train.py │ │ │ │ └── train_ddp.sh │ │ │ ├── models │ │ │ │ ├── __init__.py │ │ │ │ └── inceptionv3.py │ │ │ ├── requirements.txt │ │ │ └── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ ├── ofrecord_data_utils.py │ │ │ │ └── plot.py │ │ ├── mnasnet │ │ │ ├── README.md │ │ │ ├── eager │ │ │ │ ├── infer.py │ │ │ │ ├── infer.sh │ │ │ │ ├── train.py │ │ │ │ └── train.sh │ │ │ ├── graph │ │ │ │ ├── infer.py │ │ │ │ ├── infer.sh │ │ │ │ ├── train.py │ │ │ │ └── train.sh │ │ │ ├── model │ │ │ │ ├── __init__.py │ │ │ │ └── mnasnet.py │ │ │ └── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ ├── ofrecord_data_utils.py │ │ │ │ └── plot.py │ │ ├── mobilenetv2 │ │ │ ├── README.md │ │ │ ├── infer.py │ │ │ ├── infer.sh │ │ │ ├── models │ │ │ │ ├── __init__.py │ │ │ │ └── mobilenetv2.py │ │ │ ├── requirements.txt │ │ │ ├── train.py │ │ │ ├── train.sh │ │ │ └── utils │ │ │ │ ├── Figure_1.png │ │ │ │ ├── __init__.py │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ ├── ofrecord_data_utils.py │ │ │ │ └── plot.py │ │ ├── mobilenetv3 │ │ │ ├── README.md │ │ │ ├── infer.py │ │ │ ├── infer.sh │ │ │ ├── models │ │ │ │ ├── __init__.py │ │ │ │ └── mobilenetv3.py │ │ │ ├── requirements.txt │ │ │ ├── train.py │ │ │ ├── train.sh │ │ │ └── utils │ │ │ │ ├── Figure_1.png │ │ │ │ ├── __init__.py │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ ├── ofrecord_data_utils.py │ │ │ │ └── plot.py │ │ ├── poseNet │ │ │ ├── README.md │ │ │ ├── infer.py │ │ │ ├── infer.sh │ │ │ ├── models │ │ │ │ └── posenet.py │ │ │ ├── requirements.txt │ │ │ ├── train_oneflow.py │ │ │ ├── train_oneflow.sh │ │ │ └── utils │ │ │ │ ├── clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ └── ofrecord_data_utils.py │ │ ├── repvgg │ │ │ ├── README.md │ │ │ ├── infer.py │ │ │ ├── infer.sh │ │ │ ├── models │ │ │ │ └── repvgg.py │ │ │ ├── requirements.txt │ │ │ ├── train.py │ │ │ ├── train.sh │ │ │ └── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ ├── ofrecord_data_utils.py │ │ │ │ └── plot.py │ │ ├── resnet50 │ │ │ ├── README.md │ │ │ ├── check │ │ │ │ ├── check.py │ │ │ │ ├── check.sh │ │ │ │ ├── draw.py │ │ │ │ └── draw.sh │ │ │ ├── config.py │ │ │ ├── examples │ │ │ │ ├── infer.sh │ │ │ │ ├── infer_graph.sh │ │ │ │ ├── train_ddp_fp32.sh │ │ │ │ ├── train_ddp_stat.sh │ │ │ │ ├── train_eager.sh │ │ │ │ ├── train_eager_consistent.sh │ │ │ │ ├── train_graph.sh │ │ │ │ ├── train_graph_distributed_fp16.sh │ │ │ │ └── train_graph_distributed_fp32.sh │ │ │ ├── graph.py │ │ │ ├── infer.py │ │ │ ├── models │ │ │ │ ├── __init__.py │ │ │ │ ├── accuracy.py │ │ │ │ ├── data.py │ │ │ │ ├── optimizer.py │ │ │ │ ├── pytorch_resnet50.py │ │ │ │ └── resnet50.py │ │ │ ├── requirements.txt │ │ │ ├── train.py │ │ │ └── utils │ │ │ │ ├── Figure_1.png │ │ │ │ ├── __init__.py │ │ │ │ ├── debug.py │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── logger.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ ├── ofrecord_data_utils.py │ │ │ │ ├── plot.py │ │ │ │ ├── printer.py │ │ │ │ └── stat.py │ │ ├── resnext50_32x4d │ │ │ ├── README.md │ │ │ ├── infer.py │ │ │ ├── infer.sh │ │ │ ├── models │ │ │ │ ├── __init__.py │ │ │ │ └── resnext50_32x4d.py │ │ │ ├── requirements.txt │ │ │ ├── train.py │ │ │ ├── train.sh │ │ │ └── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ ├── ofrecord_data_utils.py │ │ │ │ └── plot.py │ │ ├── scnet │ │ │ ├── README.md │ │ │ ├── infer.py │ │ │ ├── infer.sh │ │ │ ├── models │ │ │ │ ├── resnet50.py │ │ │ │ └── scloss.py │ │ │ ├── requirements.txt │ │ │ ├── train.py │ │ │ ├── train.sh │ │ │ └── utils │ │ │ │ ├── clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ └── ofrecord_data_utils.py │ │ ├── shufflenetv2 │ │ │ ├── README.md │ │ │ ├── infer.py │ │ │ ├── infer.sh │ │ │ ├── models │ │ │ │ └── shufflenetv2.py │ │ │ ├── requirements.txt │ │ │ ├── train.py │ │ │ ├── train.sh │ │ │ └── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ ├── ofrecord_data_utils.py │ │ │ │ └── plot.py │ │ ├── swin_transformer │ │ │ ├── README.md │ │ │ ├── infer.py │ │ │ ├── infer.sh │ │ │ ├── models │ │ │ │ └── swin_transformer.py │ │ │ ├── requirements.txt │ │ │ ├── train.py │ │ │ ├── train.sh │ │ │ └── utils │ │ │ │ ├── __init__.py │ │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ │ ├── numpy_data_utils.py │ │ │ │ ├── ofrecord_data_utils.py │ │ │ │ └── plot.py │ │ └── vgg │ │ │ ├── README.md │ │ │ ├── infer.py │ │ │ ├── infer.sh │ │ │ ├── models │ │ │ ├── __init__.py │ │ │ └── vgg.py │ │ │ ├── train_oneflow.py │ │ │ ├── train_oneflow.sh │ │ │ └── utils │ │ │ ├── Figure_1.png │ │ │ ├── __init__.py │ │ │ ├── imagenet1000_clsidx_to_labels.py │ │ │ ├── numpy_data_utils.py │ │ │ ├── ofrecord_data_utils.py │ │ │ └── plot.py │ └── video │ │ └── TSN │ │ ├── README.md │ │ ├── infer.sh │ │ ├── requirements.txt │ │ ├── test_recognizer.py │ │ ├── train.sh │ │ ├── train_recognizer.py │ │ └── tsn │ │ ├── datasets │ │ ├── dataset.py │ │ └── transform.py │ │ ├── models │ │ ├── TSN.py │ │ ├── cls_head.py │ │ ├── resnet50.py │ │ ├── simple_consensus.py │ │ └── simple_spatial_module.py │ │ └── utils │ │ └── checkpoint.py ├── detection │ └── CSRNet │ │ ├── README.md │ │ ├── dataset.py │ │ ├── image.py │ │ ├── infer.py │ │ ├── infer.sh │ │ ├── model.py │ │ ├── part_A_test.json │ │ ├── part_A_train.json │ │ ├── part_A_train_with_val.json │ │ ├── part_A_val.json │ │ ├── part_B_test.json │ │ ├── part_B_train.json │ │ ├── part_B_train_with_val.json │ │ ├── part_B_val.json │ │ ├── requirement.txt │ │ ├── train.py │ │ ├── train.sh │ │ ├── transforms │ │ ├── spatial_transforms.py │ │ └── temporal_transforms.py │ │ ├── utils.py │ │ ├── val.py │ │ ├── val.sh │ │ └── vgg.py ├── gan │ ├── DCGAN │ │ ├── README.md │ │ ├── check │ │ │ ├── check.py │ │ │ └── check.sh │ │ ├── eager │ │ │ ├── train.py │ │ │ └── train.sh │ │ ├── graph │ │ │ ├── train.py │ │ │ └── train.sh │ │ ├── models.py │ │ ├── plot.py │ │ ├── test │ │ │ ├── test_of_dcgan.py │ │ │ ├── test_of_dcgan.sh │ │ │ └── test_of_dcgan_graph.sh │ │ ├── test_images.png │ │ └── utils.py │ ├── SRGAN │ │ ├── README.md │ │ ├── models │ │ │ └── of_model.py │ │ ├── requirements.txt │ │ ├── results.png │ │ ├── test_of_srgan.py │ │ ├── test_of_srgan.sh │ │ ├── train_of_srgan.py │ │ ├── train_of_srgan.sh │ │ ├── utils │ │ │ ├── of_data_utils.py │ │ │ └── of_loss.py │ │ └── vgg.py │ ├── cycleGAN │ │ ├── README.md │ │ ├── cycleGAN.py │ │ ├── download.sh │ │ ├── image.py │ │ ├── infer.py │ │ ├── infer.sh │ │ ├── networks.py │ │ ├── requirements.txt │ │ ├── train.py │ │ └── train.sh │ └── pix2pix │ │ ├── README.md │ │ ├── infer.py │ │ ├── infer.sh │ │ ├── models │ │ └── networks.py │ │ ├── requirements.txt │ │ ├── train.py │ │ ├── train.sh │ │ └── utils │ │ ├── data_utils.py │ │ ├── plot.py │ │ └── utils.py ├── oneflow_face │ ├── README.md │ ├── README_CH.md │ ├── backbones │ │ ├── __init__.py │ │ └── ir_resnet.py │ ├── configs │ │ ├── __init__.py │ │ ├── base.py │ │ ├── glint360k_mbf.py │ │ ├── glint360k_r100.py │ │ ├── glint360k_r18.py │ │ ├── glint360k_r34.py │ │ ├── glint360k_r50.py │ │ ├── ms1mv3_mbf.py │ │ ├── ms1mv3_r18.py │ │ ├── ms1mv3_r34.py │ │ ├── ms1mv3_r50.py │ │ └── speed.py │ ├── convert.sh │ ├── eval │ │ ├── __init__.py │ │ ├── onnx_helper.py │ │ ├── onnx_ijbc.py │ │ └── verification.py │ ├── function.py │ ├── graph.py │ ├── oneflow2onnx.py │ ├── requirements.txt │ ├── tools │ │ ├── mx_recordio_2_ofrecord.py │ │ └── mx_recordio_2_ofrecord_shuffled_npart.py │ ├── train.py │ ├── train_ddp.sh │ ├── train_graph_distributed.sh │ ├── utils │ │ ├── __init__.py │ │ ├── losses.py │ │ ├── ofrecord_data_utils.py │ │ ├── utils_callbacks.py │ │ ├── utils_config.py │ │ └── utils_logging.py │ ├── val.py │ └── val.sh ├── reid │ └── BoT │ │ ├── README.md │ │ ├── data_loader.py │ │ ├── infer.sh │ │ ├── loss.py │ │ ├── lr_scheduler.py │ │ ├── model.py │ │ ├── reid.py │ │ ├── requirements.txt │ │ ├── train.sh │ │ └── utils │ │ ├── __init__.py │ │ ├── distance.py │ │ └── loggers.py ├── segmentation │ ├── FODDet │ │ ├── README.md │ │ ├── model │ │ │ └── UNet.py │ │ ├── requirements.txt │ │ ├── test │ │ │ ├── dataloader.py │ │ │ ├── test.py │ │ │ ├── test.sh │ │ │ └── visualize.py │ │ └── train │ │ │ ├── train.py │ │ │ └── train.sh │ ├── FaceSeg │ │ ├── README.md │ │ ├── infer.py │ │ ├── infer.sh │ │ ├── models │ │ │ ├── LinkNet34.py │ │ │ ├── __init__.py │ │ │ └── resnet50.py │ │ ├── requirements.txt │ │ ├── train.py │ │ ├── train.sh │ │ ├── utils │ │ │ ├── __init__.py │ │ │ └── numpy_data_utils.py │ │ └── validation_oneflow.py │ └── U-Net │ │ ├── README.md │ │ ├── TrainUnetDataSet.py │ │ ├── dataloader.py │ │ ├── log.py │ │ ├── plot.py │ │ ├── predict_unet_test.py │ │ ├── requirements.txt │ │ ├── test.sh │ │ ├── train.sh │ │ └── unet.py └── style_transform │ └── fast_neural_style │ ├── README.md │ ├── infer.sh │ ├── neural_style │ ├── neural_style.py │ ├── transformer_net.py │ ├── utils.py │ └── vgg.py │ ├── requirements.txt │ └── train.sh ├── ci └── check │ └── run_py_format.py ├── dev-requirements.txt ├── ops ├── __init__.py ├── csrc │ ├── CMakeLists.txt │ ├── nms.cpp │ ├── nms.cu │ ├── roi_align.cpp │ ├── roi_align.cu │ └── roi_align.h ├── nms.py ├── roi_align.py └── test │ ├── nms_test.py │ └── roi_align_test.py └── scripts ├── compare_speed_with_pytorch.py └── swin_dataloader_compare_speed_with_pytorch.py /Audio/AM-MobileNet1D/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | OPTIONS_PATH='cfg/AM_MobileNet1D_TIMIT.cfg' 5 | PRETRAIN_MODELS='pretrain_models' 6 | 7 | if [ ! -d "$PRETRAIN_MODELS" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/audio/AM_MobileNet1D.zip 9 | unzip AM_MobileNet1D.zip 10 | rm -fr AM_MobileNet1D.zip 11 | fi 12 | 13 | python3 infer.py --cfg $OPTIONS_PATH 14 | -------------------------------------------------------------------------------- /Audio/AM-MobileNet1D/requirements.txt: -------------------------------------------------------------------------------- 1 | SoundFile 2 | tqdm 3 | oneflow 4 | numpy 5 | -------------------------------------------------------------------------------- /Audio/AM-MobileNet1D/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | DATA_PATH='data/' 5 | DATA_LISTS='data_lists' 6 | TIMIT_FOLDER='data/lisa/data/timit/raw/TIMIT' 7 | DATA_PREPARED='data_preprocessed' 8 | LABEL='data_lists/TIMIT_all.scp' 9 | OPTIONS_PATH='cfg/AM_MobileNet1D_TIMIT.cfg' 10 | 11 | if [ ! -d "$DATA_PATH" ]; then 12 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/SincNet/TIMIT.zip 13 | unzip TIMIT.zip 14 | rm -fr TIMIT.zip 15 | fi 16 | 17 | if [ ! -d "$DATA_LISTS" ]; then 18 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/AM_MobileNet1D/data_lists.zip 19 | unzip data_lists.zip 20 | rm -fr data_lists.zip 21 | fi 22 | 23 | if [ ! -d "$DATA_PREPARED" ]; then 24 | python3 utils/TIMIT_preparation.py $TIMIT_FOLDER $DATA_PREPARED $LABEL 25 | fi 26 | 27 | echo "Data prepared !" 28 | echo "Starting training ..." 29 | 30 | python3 train.py --cfg $OPTIONS_PATH 31 | -------------------------------------------------------------------------------- /Audio/Adaptive_Voice_Conversion/infer.sh: -------------------------------------------------------------------------------- 1 | python3 inference.py -a sr_24000_mel_norm/attr.pkl -c config.yaml -m vctk_model/iteration500000.pth.tar -s VCTK-Corpus/wav48/p237/p237_008.wav -t VCTK-Corpus/wav48/p292/p292_028.wav -o oneflow_avc/wav_vc_237.wav -------------------------------------------------------------------------------- /Audio/Adaptive_Voice_Conversion/preprocess/preprocess_vctk.sh: -------------------------------------------------------------------------------- 1 | . vctk.config 2 | 3 | if [ $stage -le 0 ]; then 4 | python3 make_datasets_vctk.py $raw_data_dir/wav48 $raw_data_dir/speaker-info.txt $data_dir $n_out_speakers $test_prop $sample_rate $n_utt_attr 5 | fi 6 | 7 | if [ $stage -le 1 ]; then 8 | python3 reduce_dataset.py $data_dir/train.pkl $data_dir/train_$segment_size.pkl $segment_size 9 | fi 10 | 11 | if [ $stage -le 2 ]; then 12 | # sample training samples 13 | python3 sample_single_segments.py $data_dir/train.pkl $data_dir/train_samples_$segment_size.json $training_samples $segment_size 14 | fi 15 | if [ $stage -le 3 ]; then 16 | # sample testing samples 17 | python3 sample_single_segments.py $data_dir/in_test.pkl $data_dir/in_test_samples_$segment_size.json $testing_samples $segment_size 18 | python3 sample_single_segments.py $data_dir/out_test.pkl $data_dir/out_test_samples_$segment_size.json $testing_samples $segment_size 19 | fi 20 | -------------------------------------------------------------------------------- /Audio/Adaptive_Voice_Conversion/preprocess/reduce_dataset.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | import sys 3 | 4 | pkl_path = sys.argv[1] 5 | output_path = sys.argv[2] 6 | segment_size = int(sys.argv[3]) 7 | 8 | with open(pkl_path, "rb") as f: 9 | data = pickle.load(f) 10 | 11 | reduced_data = {key: val for key, val in data.items() if val.shape[0] > segment_size} 12 | 13 | with open(output_path, "wb") as f: 14 | pickle.dump(reduced_data, f) 15 | -------------------------------------------------------------------------------- /Audio/Adaptive_Voice_Conversion/preprocess/vctk.config: -------------------------------------------------------------------------------- 1 | stage=0 2 | segment_size=128 3 | data_dir=../sr_24000_mel_norm 4 | raw_data_dir=../VCTK-Corpus 5 | n_out_speakers=20 6 | test_prop=0.1 7 | sample_rate=24000 8 | training_samples=10000000 9 | testing_samples=10000 10 | n_utt_attr=5000 11 | -------------------------------------------------------------------------------- /Audio/Adaptive_Voice_Conversion/train.sh: -------------------------------------------------------------------------------- 1 | python3 main.py -c config.yaml -d sr_24000_mel_norm -train_set train_128 -train_index_file train_samples_128.json -store_model_path vctk_model -iters 500000 -summary_step 500 > train.log 2>&1 2 | -------------------------------------------------------------------------------- /Audio/Adaptive_Voice_Conversion/utils.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | 3 | 4 | def cc(net): 5 | device = flow.device("cuda") 6 | return net.to(device) 7 | 8 | 9 | def infinite_iter(iterable): 10 | it = iter(iterable) 11 | while True: 12 | try: 13 | ret = next(it) 14 | yield ret 15 | except StopIteration: 16 | it = iter(iterable) 17 | -------------------------------------------------------------------------------- /Audio/Conv-TasNet/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.py text eol=lf 4 | *.sh text eol=lf -------------------------------------------------------------------------------- /Audio/Conv-TasNet/.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | __pycache__/ 3 | *.log 4 | egs.py 5 | egs/ 6 | nnet/compute_encoder.py 7 | *.npy -------------------------------------------------------------------------------- /Audio/Conv-TasNet/conv_tasnet_loss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Audio/Conv-TasNet/conv_tasnet_loss.png -------------------------------------------------------------------------------- /Audio/Conv-TasNet/nnet/create_scp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | @Yingzhao 4 | """ 5 | 6 | import argparse 7 | import os 8 | 9 | parser = argparse.ArgumentParser("Command to create scp file") 10 | parser.add_argument("--dataPath", type=str, required=True) 11 | parser.add_argument("--data", type=str, required=True) 12 | parser.add_argument("--scp_name", type=str, required=True) 13 | 14 | 15 | def GenerateScp(args): 16 | train_s2 = os.path.join(args.dataPath, args.data) 17 | train_s2_scp = os.path.join(args.dataPath, args.scp_name) 18 | tr_mix = open(train_s2_scp, "w") 19 | for root, dirs, files in os.walk(train_s2): 20 | files.sort() 21 | for file in files: 22 | tr_mix.write(file + " " + root + "/" + file) 23 | tr_mix.write("\n") 24 | 25 | 26 | args = parser.parse_args() 27 | GenerateScp(args) 28 | -------------------------------------------------------------------------------- /Audio/Conv-TasNet/nnet/libs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Audio/Conv-TasNet/nnet/libs/__init__.py -------------------------------------------------------------------------------- /Audio/Conv-TasNet/nnet/libs/utils.py: -------------------------------------------------------------------------------- 1 | # wujian@2018 2 | 3 | import os 4 | import json 5 | 6 | 7 | def dump_json(obj, fdir, name): 8 | """ 9 | Dump python object in json 10 | """ 11 | if fdir and not os.path.exists(fdir): 12 | os.makedirs(fdir) 13 | with open(os.path.join(fdir, name), "w") as f: 14 | json.dump(obj, f, indent=4, sort_keys=False) 15 | -------------------------------------------------------------------------------- /Audio/Conv-TasNet/requirements.txt: -------------------------------------------------------------------------------- 1 | torch==1.0.0 2 | tqdm==4.26.0 3 | numpy==1.15.2 4 | scipy==1.1.0 -------------------------------------------------------------------------------- /Audio/CycleGAN-VC2/README.md: -------------------------------------------------------------------------------- 1 | # CycleGan-VC2 with oneflow 2 | 3 | Implementation of [CycleGan-VC2](https://arxiv.org/abs/1904.04631) with Oneflow. 4 | 5 | Non-parallel voice conversion (VC) is a technique for **learning the mapping from source to target speech without relying on parallel data**. 6 | CycleGAN-VC2 is an improved version of CycleGAN-VC incorporating three new techniques: an improved objective (two-step adversarial losses), improved generator (2-1-2D CNN), and improved discriminator (PatchGAN). 7 | 8 | 9 | ## Requirement 10 | 11 | ```bash 12 | pip install -r requirements.txt 13 | ``` 14 | 15 | 16 | ## Train 17 | 18 | ```bash 19 | bash train.sh 20 | ``` 21 | 22 | 23 | ## Infer 24 | 25 | ```bash 26 | bash infer.sh 27 | ``` 28 | 29 | -------------------------------------------------------------------------------- /Audio/CycleGAN-VC2/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | PRETRAIN_MODELS='pretrain_models' 5 | DATA_PATH='sample/' 6 | 7 | if [ ! -d "$PRETRAIN_MODELS" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/CycleGan-VC2/pretrain_models.zip 9 | unzip pretrain_models.zip 10 | rm -fr pretrain_models.zip 11 | fi 12 | 13 | if [ ! -d "$DATA_PATH" ]; then 14 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/CycleGan-VC2/sample.zip 15 | unzip sample.zip 16 | rm -fr sample.zip 17 | fi 18 | 19 | echo "Starting infering ..." 20 | 21 | python3 infer.py 22 | -------------------------------------------------------------------------------- /Audio/CycleGAN-VC2/requirements.txt: -------------------------------------------------------------------------------- 1 | oneflow 2 | librosa 3 | tqdm 4 | pyworld 5 | -------------------------------------------------------------------------------- /Audio/CycleGAN-VC2/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | DATA_PATH='data/' 5 | DATA_PREPARED='cache/' 6 | 7 | if [ ! -d "$DATA_PATH" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/CycleGan-VC2/data.zip 9 | unzip data.zip 10 | rm -fr data.zip 11 | fi 12 | 13 | if [ ! -d "$DATA_PREPARED" ]; then 14 | python3 utils/data_preprocess.py 15 | fi 16 | 17 | echo "Data prepared !" 18 | echo "Starting training ..." 19 | 20 | python3 train.py 21 | -------------------------------------------------------------------------------- /Audio/MaskCycleGAN-VC/README.md: -------------------------------------------------------------------------------- 1 | # MaskCycleGAN-VC with oneflow 2 | 3 | Implementation of [MaskCycleGAN-VC](https://arxiv.org/pdf/2102.12841.pdf) with Oneflow. 4 | 5 | Non-parallel voice conversion (VC) is a technique for training voice converters without a parallel corpus. MaskCycleGAN-VC is the state of the art method for non-parallel voice conversion using CycleGAN. It is trained using a novel auxiliary task of filling in frames (FIF) by applying a temporal mask to the input Mel-spectrogram. It demonstrates marked improvements over prior models such as CycleGAN-VC (2018), CycleGAN-VC2 (2019), and CycleGAN-VC3 (2020). 6 | 7 | 8 | ## Requirement 9 | 10 | ```bash 11 | pip install -r requirements.txt 12 | ``` 13 | 14 | 15 | ## Train 16 | 17 | ```bash 18 | sh train.sh 19 | ``` 20 | 21 | 22 | ## Infer 23 | 24 | ```bash 25 | sh infer.sh 26 | ``` 27 | -------------------------------------------------------------------------------- /Audio/MaskCycleGAN-VC/infer.py: -------------------------------------------------------------------------------- 1 | """ 2 | @author: Wang Yizhang <1739601638@qq.com> 3 | """ 4 | from args.cycleGAN_arg_parser import CycleGANArgParser 5 | from model.trainer import MaskCycleGANVCTrainer 6 | 7 | 8 | if __name__ == "__main__": 9 | parser = CycleGANArgParser() 10 | args = parser.parse_args() 11 | cycleGAN = MaskCycleGANVCTrainer(args) 12 | cycleGAN.infer() 13 | -------------------------------------------------------------------------------- /Audio/MaskCycleGAN-VC/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | PRETRAIN_MODELS='pretrain_models' 5 | DATA_PATH='sample/' 6 | 7 | if [ ! -d "$PRETRAIN_MODELS" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/MaskCycleGAN-VC/pretrain_models.zip 9 | unzip pretrain_models.zip 10 | rm -fr pretrain_models.zip 11 | fi 12 | 13 | if [ ! -d "$DATA_PATH" ]; then 14 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/MaskCycleGAN-VC/sample.zip 15 | unzip sample.zip 16 | rm -fr sample.zip 17 | fi 18 | 19 | echo "Starting infering ..." 20 | 21 | python3 infer.py \ 22 | --pretrain_models pretrain_models \ 23 | --infer_data_dir sample \ 24 | --decay_after 2e5 \ 25 | --batch_size 9 \ 26 | --sample_rate 22050 \ 27 | --num_frames 64 \ 28 | --max_mask_len 25 29 | -------------------------------------------------------------------------------- /Audio/MaskCycleGAN-VC/requirements.txt: -------------------------------------------------------------------------------- 1 | oneflow 2 | librosa 3 | tqdm 4 | pyworld -------------------------------------------------------------------------------- /Audio/MaskCycleGAN-VC/train.py: -------------------------------------------------------------------------------- 1 | """ 2 | @author: Wang Yizhang <1739601638@qq.com> 3 | """ 4 | from args.cycleGAN_arg_parser import CycleGANArgParser 5 | from model.trainer import MaskCycleGANVCTrainer 6 | 7 | 8 | if __name__ == "__main__": 9 | parser = CycleGANArgParser() 10 | args = parser.parse_args() 11 | cycleGAN = MaskCycleGANVCTrainer(args) 12 | cycleGAN.train() 13 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/average.sh: -------------------------------------------------------------------------------- 1 | python3 tools/average.py egs/aishell/exp/transformer_baseline 70 79 -------------------------------------------------------------------------------- /Audio/OpenTransformer/egs/aishell/conf/rnnlm.yaml: -------------------------------------------------------------------------------- 1 | data: 2 | name: aishell 3 | dataset_type: text 4 | vocab: egs/aishell/data/vocab 5 | batch_size: 16 6 | src_vocab: egs/aishell/data/vocab 7 | tgt_vocab: egs/aishell/data/vocab 8 | train: 9 | src: ['egs/aishell/data/train/text'] 10 | tgt: ['egs/aishell/data/train/text'] 11 | model: 12 | type: rnn_lm 13 | vocab_size: 4233 14 | num_layers: 2 15 | hidden_size: 1024 16 | residual_dropout: 0.1 17 | smoothing: 0.1 18 | dropout: 0.1 19 | share_embedding: True 20 | train: 21 | optimizer_type: adam 22 | optimizer: 23 | lr: 0.001 24 | betas: [0.9, 0.98] 25 | eps: 1.0e-9 26 | weight_decay: 1.0e-6 27 | amsgrad: False 28 | scheduler_type: step-linear 29 | scheduler: 30 | final_step: 100000 31 | start_lr: 1.0e-3 32 | final_lr: 1.0e-6 33 | clip_grad: 5 34 | epochs: 60 35 | accum_steps: 4 36 | grad_noise: 0.0 37 | load_model: False 38 | save_name: rnn_lm_baseline -------------------------------------------------------------------------------- /Audio/OpenTransformer/egs/aishell/conf/transformer_lm.yaml: -------------------------------------------------------------------------------- 1 | data: 2 | name: aishell 3 | dataset_type: text 4 | vocab: egs/aishell/data/vocab 5 | batch_size: 16 6 | src_vocab: egs/aishell/data/vocab 7 | tgt_vocab: egs/aishell/data/vocab 8 | train: 9 | src: ['egs/aishell/data/train/text'] 10 | tgt: ['egs/aishell/data/train/text'] 11 | model: 12 | type: transformer_lm 13 | vocab_size: 4233 14 | num_blocks: 6 15 | d_model: 256 16 | n_heads: 4 17 | d_ff: 1024 18 | residual_dropout: 0.1 19 | smoothing: 0.1 20 | share_embedding: True 21 | train: 22 | optimizer_type: adam 23 | optimizer: 24 | lr: 0.001 25 | betas: [0.9, 0.98] 26 | eps: 1.0e-9 27 | weight_decay: 1.0e-6 28 | amsgrad: False 29 | scheduler_type: transformer 30 | scheduler: 31 | model_size: 256 32 | warmup_steps: 12000 33 | factor: 1.0 34 | clip_grad: 5 35 | epochs: 60 36 | accum_steps: 4 37 | grad_noise: 0.0 38 | load_model: False 39 | save_name: transformer_lm_baseline -------------------------------------------------------------------------------- /Audio/OpenTransformer/egs/aishell/local/generate_vocab.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | 5 | text_in = sys.argv[1] 6 | vocab_out = sys.argv[2] 7 | 8 | lexicon = {} 9 | with open(text_in, "r", encoding="utf-8") as f: 10 | for line in f: 11 | parts = line.strip().split() 12 | idx = parts[0] 13 | phones = parts[1:] 14 | 15 | for p in phones: 16 | if p not in lexicon: 17 | lexicon[p] = 1 18 | else: 19 | lexicon[p] += 1 20 | 21 | print("There are %d label in lexicon!" % len(lexicon)) 22 | 23 | vocab = sorted(lexicon.items(), key=lambda x: x[1], reverse=True) 24 | 25 | index = 3 26 | with open(vocab_out, "w") as w: 27 | w.write(" 0\n") 28 | w.write(" 1\n") 29 | w.write(" 2\n") 30 | for (l, n) in vocab: 31 | w.write(l + " " + str(index) + "\n") 32 | index += 1 33 | 34 | print("Done!") 35 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/egs/aishell/local/split_and_norm.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | text_in = sys.argv[1] 4 | text_out = sys.argv[2] 5 | 6 | 7 | def text_norm(seq): 8 | new_seq = "" 9 | for s in seq: 10 | inside_code = ord(s) 11 | if inside_code == 12288: 12 | inside_code = 32 13 | elif inside_code >= 65281 and inside_code <= 65374: 14 | inside_code -= 65248 15 | 16 | new_s = chr(inside_code) 17 | 18 | if new_s.encode("UTF-8").isalpha(): 19 | new_s = new_s.upper() 20 | 21 | new_seq += new_s 22 | new_seq += " " 23 | 24 | return " ".join(new_seq.split()) 25 | 26 | 27 | with open(text_in, "r", encoding="utf-8") as f1: 28 | with open(text_out, "w", encoding="utf-8") as f2: 29 | for line in f1: 30 | parts = line.strip().split() 31 | utt_id = parts[0] 32 | norm_text = text_norm(" ".join(parts[1:])) 33 | f2.write(utt_id + " " + norm_text + "\n") 34 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/egs/aishell/path.sh: -------------------------------------------------------------------------------- 1 | KALDI_ROOT='~/kaldi' -------------------------------------------------------------------------------- /Audio/OpenTransformer/egs/aishell/run.sh: -------------------------------------------------------------------------------- 1 | . ./path.sh || exit 1; 2 | 3 | stage=-1 4 | 5 | data=/home/data 6 | data_url=www.openslr.org/resources/33 7 | 8 | set -e 9 | set -u 10 | set -o pipefail 11 | 12 | chmod u+x local/* || exit 1; 13 | 14 | if [ ${stage} -le -1 ]; then 15 | ### Task dependent. You have to make data the following preparation part by yourself. 16 | ### But you can utilize Kaldi recipes in most cases 17 | echo "stage 0: Data preparation" 18 | 19 | sh local/download_and_untar.sh $data $data_url data_aishell || exit 1; 20 | sh local/download_and_untar.sh $data $data_url resource_aishell || exit 1; 21 | 22 | sh local/aishell_data_prep.sh $data/data_aishell/wav $data/data_aishell/transcript || exit 1; 23 | 24 | for name in train test dev;do 25 | python local/split_and_norm.py data/$name/text.org data/$name/text || exit 1; 26 | done 27 | 28 | # prepare vocabulary! 29 | python local/generate_vocab.py data/train/text data/vocab || exit 1; 30 | 31 | fi -------------------------------------------------------------------------------- /Audio/OpenTransformer/eval.sh: -------------------------------------------------------------------------------- 1 | python3 eval.py -m egs/aishell/exp/transformer_baseline/model.average.from70to79.pt -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Audio/OpenTransformer/otrans/__init__.py -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/decoder/__init__.py: -------------------------------------------------------------------------------- 1 | from otrans.decoder.transformer import TransformerDecoder 2 | 3 | 4 | BuildDecoder = {"transformer": TransformerDecoder} 5 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/decoder/base.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | import oneflow.nn as nn 3 | 4 | 5 | class BaseDecoder(nn.Module): 6 | def __init__(self): 7 | super(BaseDecoder, self).__init__() 8 | 9 | def forward(self, targets, **kwargs): 10 | raise NotImplementedError 11 | 12 | def inference(self, tokens, **kargs): 13 | raise NotImplementedError 14 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/decoder/utils.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | 3 | 4 | def get_transformer_decoder_mask(targets): 5 | batch_size, steps = targets.size() 6 | seq_mask = flow.ones([batch_size, steps, steps], device=targets.device) 7 | seq_mask = flow.tril(seq_mask).to(flow.int8) 8 | return seq_mask 9 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/encoder/__init__.py: -------------------------------------------------------------------------------- 1 | from otrans.encoder.transformer import TransformerEncoder 2 | from otrans.encoder.conformer import ConformerEncoder 3 | 4 | 5 | BuildEncoder = { 6 | "transformer": TransformerEncoder, 7 | "conformer": ConformerEncoder, 8 | } 9 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/encoder/base.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | import oneflow.nn as nn 3 | 4 | 5 | class BaseEncoder(nn.Module): 6 | def __init__(self): 7 | super(BaseEncoder, self).__init__() 8 | 9 | def forward(self, inputs, inputs_mask, **kargs): 10 | raise NotImplementedError 11 | 12 | def inference(self, inputs, inputs_mask, cache=None, **kargs): 13 | raise NotImplementedError 14 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/encoder/utils.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | import oneflow.nn as nn 3 | 4 | 5 | def get_length_mask(tensor, tensor_length): 6 | b, t, _ = tensor.size() 7 | mask = tensor.new_zeros([b, t], dtype=flow.int8) 8 | for i, length in enumerate(tensor_length): 9 | length = length.item() 10 | mask[i].narrow(0, 0, length).fill_(1) 11 | return mask > 0 12 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/frontend/__init__.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | import oneflow.nn as nn 3 | from .concat import * 4 | from .conv import ConvFrontEnd 5 | from otrans.frontend.base import BaseFrontEnd 6 | 7 | 8 | BuildFrontEnd = { 9 | "concat": ConcatFeatureFrontEnd, 10 | "concat-with-linear": ConcatWithLinearFrontEnd, 11 | "conv": ConvFrontEnd, 12 | } 13 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/frontend/base.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | import oneflow.nn as nn 3 | 4 | 5 | class BaseFrontEnd(nn.Module): 6 | def __init__(self): 7 | super(BaseFrontEnd, self).__init__() 8 | 9 | def forward(self, inputs, inputs_mask): 10 | raise NotImplementedError 11 | 12 | def inference(self, inputs, inputs_mask): 13 | return self.forward(inputs, inputs_mask) 14 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/model/__init__.py: -------------------------------------------------------------------------------- 1 | from .ctc import CTCModel 2 | from .speech2text import SpeechToText 3 | from .lm import RecurrentLanguageModel, TransformerLanguageModel 4 | 5 | 6 | End2EndModel = {"ctc": CTCModel, "speech2text": SpeechToText} 7 | 8 | LanguageModel = { 9 | "rnn_lm": RecurrentLanguageModel, 10 | "transformer_lm": TransformerLanguageModel, 11 | } 12 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/model/base.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | import oneflow.nn as nn 3 | 4 | 5 | class BaseModel(nn.Module): 6 | def __init__(self): 7 | super(BaseModel, self).__init__() 8 | 9 | def forward_hook(self, step, epoch, **kwargs): 10 | pass 11 | 12 | def forward(self, inputs, targets): 13 | raise NotImplementedError 14 | 15 | def VisualizationHook(self, idx=0): 16 | return None 17 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/module/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/otrans/train/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/tools/computer_wer.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import editdistance 3 | 4 | tgt_file = sys.argv[1] 5 | dec_file = sys.argv[2] 6 | 7 | total_words = 0 8 | total_false = 0 9 | 10 | target_dict = {} 11 | with open(tgt_file, "r", encoding="utf-8") as tf: 12 | for line in tf: 13 | parts = line.strip().split() 14 | idx = parts[0] 15 | words = parts[1:] 16 | target_dict[idx] = words 17 | 18 | with open(dec_file, "r", encoding="utf-8") as df: 19 | for line in df: 20 | parts = line.strip().split() 21 | idx = parts[0] 22 | words = parts[1:] 23 | ref_words = target_dict[idx] 24 | total_words += len(ref_words) 25 | diff = editdistance.eval(ref_words, words) 26 | total_false += diff 27 | 28 | print("The WER/CER is %.2f" % 100 * total_false / total_words) 29 | -------------------------------------------------------------------------------- /Audio/OpenTransformer/train.sh: -------------------------------------------------------------------------------- 1 | python3 run.py -c egs/aishell/conf/transformer_baseline.yaml > train.log 2>&1 -------------------------------------------------------------------------------- /Audio/SincNet/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | OPTIONS_PATH='cfg/SincNet_TIMIT.cfg' 5 | PRETRAIN_MODELS='pretrain_models' 6 | 7 | if [ ! -d "$PRETRAIN_MODELS" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/audio/SincNet.zip 9 | unzip SincNet.zip 10 | rm -fr SincNet.zip 11 | fi 12 | 13 | python infer.py --cfg $OPTIONS_PATH 14 | -------------------------------------------------------------------------------- /Audio/SincNet/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | DATA_PATH='data/' 5 | DATA_LISTS='data_lists' 6 | TIMIT_FOLDER='data/lisa/data/timit/raw/TIMIT' 7 | DATA_PREPARED='data_preprocessed' 8 | LABEL='data_lists/TIMIT_all_upper.scp' 9 | OPTIONS_PATH='cfg/SincNet_TIMIT.cfg' 10 | 11 | if [ ! -d "$DATA_PATH" ]; then 12 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/SincNet/TIMIT.zip 13 | unzip TIMIT.zip 14 | rm -fr TIMIT.zip 15 | fi 16 | 17 | if [ ! -d "$DATA_LISTS" ]; then 18 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/SincNet/data_lists.zip 19 | unzip data_lists.zip 20 | rm -fr data_lists.zip 21 | fi 22 | 23 | if [ ! -d "$DATA_PREPARED" ]; then 24 | python utils/TIMIT_preparation.py $TIMIT_FOLDER $DATA_PREPARED $LABEL 25 | fi 26 | 27 | echo "Data prepared !" 28 | echo "Starting training ..." 29 | 30 | python train.py --cfg $OPTIONS_PATH 31 | -------------------------------------------------------------------------------- /Audio/Speech-Emotion-Analyzer/.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /Audio/Speech-Emotion-Analyzer/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Audio/Speech-Emotion-Analyzer/models/__init__.py: -------------------------------------------------------------------------------- 1 | from .cnn1d_ser import cnn1d_ser 2 | from .lstm_ser import lstm_ser 3 | -------------------------------------------------------------------------------- /Audio/Speech-Emotion-Analyzer/models/lstm_ser.py: -------------------------------------------------------------------------------- 1 | from .lstm_oneflow import LSTM 2 | import oneflow.nn as nn 3 | 4 | 5 | class lstm_ser(nn.Module): 6 | def __init__(self, input_dim, hidden_dim, output_dim, batch_size): 7 | super(lstm_ser, self).__init__() 8 | self.classifier = nn.Sequential( 9 | LSTM(input_dim, hidden_dim, batch_size), 10 | nn.Dropout(0.5), 11 | nn.Linear(hidden_dim, 32), 12 | nn.ReLU(), 13 | nn.Linear(32, output_dim), 14 | ) 15 | 16 | def forward(self, x): 17 | logits = self.classifier(x) 18 | return logits 19 | -------------------------------------------------------------------------------- /Audio/Speech-Emotion-Analyzer/predict.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | OPTIONS_PATH='configs/lstm.yaml' 5 | 6 | python predict.py --config $OPTIONS_PATH 7 | -------------------------------------------------------------------------------- /Audio/Speech-Emotion-Analyzer/preprocess.py: -------------------------------------------------------------------------------- 1 | """Extracting and saving the features of the audio in the dataset""" 2 | import extract_feats.opensmile as of 3 | import extract_feats.librosa as lf 4 | from utils import parse_opt 5 | import os 6 | 7 | 8 | config = parse_opt() 9 | os.makedirs(config.checkpoint_path) 10 | os.makedirs(config.feature_path) 11 | 12 | if config.feature_method == "o": 13 | of.get_data( 14 | config, config.data_path, config.train_feature_path_opensmile, train=True 15 | ) 16 | 17 | elif config.feature_method == "l": 18 | lf.get_data(config, config.data_path, config.train_feature_path_librosa, train=True) 19 | -------------------------------------------------------------------------------- /Audio/Speech-Emotion-Analyzer/requirements.txt: -------------------------------------------------------------------------------- 1 | oneflow==0.5.0 2 | scikit-learn==0.21.1 3 | numpy==1.16.3 4 | librosa==0.6.3 5 | scipy==1.3.0 6 | pandas==0.24.2 7 | matplotlib==2.2.2 8 | -------------------------------------------------------------------------------- /Audio/Speech-Emotion-Analyzer/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | OPTIONS_PATH='configs/lstm.yaml' 5 | 6 | python preprocess.py --config $OPTIONS_PATH 7 | 8 | echo "Data prepared !" 9 | echo "Starting training ..." 10 | 11 | python train.py --config $OPTIONS_PATH 12 | 13 | echo "Train done!" 14 | -------------------------------------------------------------------------------- /Audio/Speech-Emotion-Analyzer/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .opts import parse_opt 2 | from .plot import * 3 | -------------------------------------------------------------------------------- /Audio/Speech-Transformer/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | 3 | src/utils/kaldi_io.py 4 | 5 | tools/kaldi-io-for-python/ 6 | tools/kaldi 7 | 8 | egs/*/data 9 | egs/*/dump 10 | egs/*/fbank 11 | egs/*/exp 12 | 13 | # MISC 14 | .DS_Store 15 | .nfs* 16 | .vscode 17 | __pycache__ 18 | nohup.out 19 | -------------------------------------------------------------------------------- /Audio/Speech-Transformer/egs/aishell/cmd.sh: -------------------------------------------------------------------------------- 1 | # you can change cmd.sh depending on what type of queue you are using. 2 | # If you have no queueing system and want to run on a local machine, you 3 | # can change all instances 'queue.pl' to run.pl (but be careful and run 4 | # commands one by one: most recipes will exhaust the memory on your 5 | # machine). queue.pl works with GridEngine (qsub). slurm.pl works 6 | # with slurm. Different queues are configured differently, with different 7 | # queue names and different ways of specifying things like memory; 8 | # to account for these differences you can create and edit the file 9 | # conf/queue.conf to match your queue's configuration. Search for 10 | # conf/queue.conf in http://kaldi-asr.org/doc/queue.html for more information, 11 | # or search for the string 'default_config' in utils/queue.pl or utils/slurm.pl. 12 | 13 | export train_cmd="run.pl --mem 2G" 14 | export cuda_cmd="run.pl --mem 2G --gpu 1" 15 | export decode_cmd="run.pl --mem 4G" 16 | -------------------------------------------------------------------------------- /Audio/Speech-Transformer/egs/aishell/conf/fbank.conf: -------------------------------------------------------------------------------- 1 | --sample-frequency=16000 2 | --num-mel-bins=80 -------------------------------------------------------------------------------- /Audio/Speech-Transformer/egs/aishell/figures/tr_val_loss_15000bf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Audio/Speech-Transformer/egs/aishell/figures/tr_val_loss_15000bf.png -------------------------------------------------------------------------------- /Audio/Speech-Transformer/egs/aishell/local/score.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ -f path.sh ] && . ./path.sh 4 | 5 | nlsyms="" 6 | 7 | . utils/parse_options.sh 8 | 9 | if [ $# != 2 ]; then 10 | echo "Usage: $0 " 11 | exit 1 12 | fi 13 | 14 | dir=$1 15 | dic=$2 16 | 17 | json2trn.py ${dir}/data.json ${dic} ${dir}/ref.trn ${dir}/hyp.trn 18 | 19 | if [ ! -z ${nlsyms} ]; then 20 | cp ${dir}/ref.trn ${dir}/ref.trn.org 21 | cp ${dir}/hyp.trn ${dir}/hyp.trn.org 22 | filt.py -v $nlsyms ${dir}/ref.trn.org > ${dir}/ref.trn 23 | filt.py -v $nlsyms ${dir}/hyp.trn.org > ${dir}/hyp.trn 24 | fi 25 | 26 | sclite -r ${dir}/ref.trn trn -h ${dir}/hyp.trn trn -i rm -o all stdout > ${dir}/result.txt 27 | 28 | echo "write a CER (or TER) result in ${dir}/result.txt" 29 | grep -e Avg -e SPKR -m 2 ${dir}/result.txt 30 | -------------------------------------------------------------------------------- /Audio/Speech-Transformer/egs/aishell/path.sh: -------------------------------------------------------------------------------- 1 | MAIN_ROOT=$PWD/../.. 2 | KALDI_ROOT=$MAIN_ROOT/tools/kaldi 3 | SRC_ROOT=$MAIN_ROOT/src 4 | 5 | # BEGIN from kaldi path.sh 6 | [ -f $KALDI_ROOT/tools/env.sh ] && . $KALDI_ROOT/tools/env.sh 7 | export PATH=$PWD/utils/:$KALDI_ROOT/tools/openfst/bin:$KALDI_ROOT/tools/sctk/bin:$PWD:$PATH 8 | [ ! -f $KALDI_ROOT/tools/config/common_path.sh ] && echo >&2 "The standard file $KALDI_ROOT/tools/config/common_path.sh is not present -> Exit!" && exit 1 9 | . $KALDI_ROOT/tools/config/common_path.sh 10 | export LC_ALL=C 11 | # END 12 | 13 | export PATH=$SRC_ROOT/bin/:$SRC_ROOT/utils/:$PATH 14 | export PYTHONPATH=$SRC_ROOT/data/:$SRC_ROOT/transformer/:$SRC_ROOT/solver/:$SRC_ROOT/utils/:$PYTHONPATH 15 | -------------------------------------------------------------------------------- /Audio/Speech-Transformer/egs/aishell/steps: -------------------------------------------------------------------------------- 1 | ../../tools/kaldi/egs/wsj/s5/steps -------------------------------------------------------------------------------- /Audio/Speech-Transformer/egs/aishell/utils: -------------------------------------------------------------------------------- 1 | ../../tools/kaldi/egs/wsj/s5/utils -------------------------------------------------------------------------------- /Audio/Speech-Transformer/src/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Audio/Speech-Transformer/src/__init__.py -------------------------------------------------------------------------------- /Audio/Speech-Transformer/src/data/__init__.py: -------------------------------------------------------------------------------- 1 | from .data import AudioDataLoader, AudioDataset -------------------------------------------------------------------------------- /Audio/Speech-Transformer/src/solver/__init__.py: -------------------------------------------------------------------------------- 1 | from .solver import Solver 2 | -------------------------------------------------------------------------------- /Audio/Speech-Transformer/src/transformer/__init__.py: -------------------------------------------------------------------------------- 1 | from .decoder import Decoder 2 | from .encoder import Encoder 3 | from .attention import MultiHeadAttention 4 | from .transformer import Transformer 5 | from .optimizer import TransformerOptimizer 6 | from .loss import cal_performance 7 | from .module import PositionalEncoding, PositionwiseFeedForward 8 | -------------------------------------------------------------------------------- /Audio/Speech-Transformer/src/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .utils import process_dict 2 | from .utils import ( 3 | IGNORE_ID, 4 | get_attn_key_pad_mask, 5 | get_attn_pad_mask, 6 | get_non_pad_mask, 7 | get_subsequent_mask, 8 | pad_list, 9 | ) 10 | from .utils import get_non_pad_mask, get_attn_pad_mask 11 | -------------------------------------------------------------------------------- /Audio/Speech-Transformer/src/utils/scp2json.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | # encoding: utf-8 3 | 4 | # Copyright 2017 Johns Hopkins University (Shinji Watanabe) 5 | # Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0) 6 | 7 | import sys 8 | import json 9 | import argparse 10 | 11 | if __name__ == "__main__": 12 | parser = argparse.ArgumentParser() 13 | parser.add_argument("--key", "-k", type=str, help="key") 14 | args = parser.parse_args() 15 | 16 | l = {} 17 | line = sys.stdin.readline() 18 | while line: 19 | x = unicode(line, "utf_8").rstrip().split() 20 | v = {args.key: " ".join(x[1:]).encode("utf_8")} 21 | l[x[0].encode("utf_8")] = v 22 | line = sys.stdin.readline() 23 | 24 | all_l = {"utts": l} 25 | 26 | # ensure "ensure_ascii=False", which is a bug 27 | jsonstring = json.dumps(all_l, indent=4, ensure_ascii=False) 28 | print(jsonstring) 29 | -------------------------------------------------------------------------------- /Audio/Speech-Transformer/tools/Makefile: -------------------------------------------------------------------------------- 1 | KALDI = 2 | 3 | .PHONY: all clean 4 | 5 | all: kaldi kaldi-io-for-python 6 | 7 | kaldi-io-for-python: 8 | # git clone https://github.com/vesis84/kaldi-io-for-python.git 9 | tar -zxvf kaldi-io-for-python.tar.gz 10 | cd ../src/utils; ln -s ../../tools/kaldi-io-for-python/kaldi_io.py 11 | 12 | ifneq ($(strip $(KALDI)),) 13 | kaldi: 14 | ln -s $(KALDI) kaldi 15 | else 16 | kaldi: 17 | # git clone https://github.com/kaldi-asr/kaldi.git kaldi_github; cd kaldi_github/tools; $(MAKE) all 18 | # cd kaldi_github/src; ./configure --shared --use-cuda=no; $(MAKE) depend; $(MAKE) all 19 | # ln -nfs kaldi_github kaldi 20 | endif 21 | 22 | clean: 23 | rm -fr kaldi kaldi-io-for-python ../src/utils/kaldi_io.py 24 | -------------------------------------------------------------------------------- /Audio/Speech-Transformer/tools/kaldi-io-for-python.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Audio/Speech-Transformer/tools/kaldi-io-for-python.tar.gz -------------------------------------------------------------------------------- /Audio/StarGAN-VC/README.md: -------------------------------------------------------------------------------- 1 | # StarGAN-VC with oneflow 2 | 3 | Implementation of [StarGAN-VC](https://arxiv.org/abs/1806.02169) with Oneflow. 4 | 5 | StarGAN-VC is noteworthy in that it (1) requires no parallel utterances, transcriptions, or time alignment procedures for speech generator training, (2) simultaneously learns many-to-many mappings across different attribute domains using a single generator network, (3) is able to generate converted speech signals quickly enough to allow real-time implementations and (4) requires only several minutes of training examples to generate reasonably realistic-sounding speech. 6 | 7 | 8 | ## Requirement 9 | 10 | ```bash 11 | pip install -r requirements.txt 12 | ``` 13 | 14 | 15 | ## Train 16 | 17 | ```bash 18 | sh train.sh 19 | ``` 20 | 21 | 22 | ## Infer 23 | 24 | ```bash 25 | sh infer.sh 26 | ``` 27 | -------------------------------------------------------------------------------- /Audio/StarGAN-VC/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | PRETRAIN_MODELS='pretrain_models' 5 | 6 | if [ ! -d "$PRETRAIN_MODELS" ]; then 7 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/StarGAN-VC/pretrain_models.zip 8 | unzip pretrain_models.zip 9 | rm -fr pretrain_models.zip 10 | fi 11 | 12 | echo "Starting infering ..." 13 | 14 | python3 main.py \ 15 | --mode test \ 16 | --src_speaker TM1 --trg_speaker "['TM1','SF1']" 17 | -------------------------------------------------------------------------------- /Audio/StarGAN-VC/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | librosa 3 | oneflow 4 | SoundFile 5 | pyworld 6 | scikit_learn 7 | -------------------------------------------------------------------------------- /Audio/StarGAN-VC/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | TRAIN_DATA='vcc2016_training.zip' 5 | TEST_DATA='evaluation_all.zip' 6 | 7 | if [ ! -f "$TRAIN_DATA" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/StarGAN-VC/vcc2016_training.zip 9 | fi 10 | 11 | if [ ! -f "$TEST_DATA" ]; then 12 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/StarGAN-VC/evaluation_all.zip 13 | fi 14 | 15 | python3 utils/preprocess.py 16 | 17 | echo "Data prepared !" 18 | echo "Starting training ..." 19 | 20 | python3 main.py 21 | -------------------------------------------------------------------------------- /Audio/Wav2Letter/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="save_models" 4 | 5 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 6 | mkdir $PRETRAIN_MODEL_PATH 7 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/audio/wav2letter.zip 8 | unzip -d $PRETRAIN_MODEL_PATH ./wav2letter.zip 9 | fi 10 | 11 | python infer.py 12 | -------------------------------------------------------------------------------- /Audio/Wav2Letter/requirements.txt: -------------------------------------------------------------------------------- 1 | oneflow 2 | sonopy 3 | scipy 4 | tqdm 5 | Levenshtein 6 | -------------------------------------------------------------------------------- /Audio/Wav2Letter/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | DATA_PATH="speech_data" 4 | 5 | if [ ! -d “$DATA_PATH” ]; then 6 | wget http://download.tensorflow.org/data/speech_commands_v0.01.tar.gz 7 | mkdir $DATA_PATH && mkdir $DATA_PATH/speech_commands_v0.01 8 | tar -zxvf speech_commands_v0.01.tar.gz -C $DATA_PATH/speech_commands_v0.01 9 | rm -fr speech_commands_v0.01.tar.gz 10 | fi 11 | echo "Data download success!" 12 | 13 | python Wav2Letter/data.py 14 | echo "Data proprecessed!" 15 | 16 | python train.py 17 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(models) 3 | add_subdirectory(ops/csrc) 4 | -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/0.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/1.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/2.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/3.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/4.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/5.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/6.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/7.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/8.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/9.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/background-black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/background-black.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/base.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/base.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/pipe-green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/pipe-green.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/redbird-downflap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/redbird-downflap.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/redbird-midflap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/redbird-midflap.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/assets/sprites/redbird-upflap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/DeepReinforcementLearning/FlappyBird/assets/sprites/redbird-upflap.png -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/model/utils.py: -------------------------------------------------------------------------------- 1 | """ 2 | @author: Chenhao Lu 3 | @author: Yizhang Wang <1739601638@qq.com> 4 | """ 5 | import cv2 6 | import numpy as np 7 | 8 | 9 | def pre_processing(image, width, height): 10 | image = cv2.cvtColor(cv2.resize(image, (width, height)), cv2.COLOR_BGR2GRAY) 11 | _, image = cv2.threshold(image, 1, 255, cv2.THRESH_BINARY) 12 | return image[None, :, :].astype(np.float32) 13 | -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | pygame 3 | opencv_python -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/test_flappy_bird.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="flappybird_pretrain_model" 4 | 5 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 6 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/rl/flappybird_pretrain_model.zip 7 | unzip flappybird_pretrain_model.zip 8 | fi 9 | 10 | python3 test.py --saved_path $PRETRAIN_MODEL_PATH -------------------------------------------------------------------------------- /DeepReinforcementLearning/FlappyBird/train_flappy_bird.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | CHECKPOINT_PATH="checkpoints" 4 | if [ ! -d "$CHECKPOINT_PATH" ]; then 5 | mkdir $CHECKPOINT_PATH 6 | fi 7 | 8 | LEARNING_RATE=1e-6 9 | OPTIMIZER="adam" 10 | EPOCH=2000000 11 | BATCH_SIZE=32 12 | REPLAY_MEMORY_SIZE=50000 13 | 14 | 15 | python3 train.py \ 16 | --save_checkpoint_path $CHECKPOINT_PATH \ 17 | --lr $LEARNING_RATE \ 18 | --optimizer $OPTIMIZER \ 19 | --num_iters $EPOCH \ 20 | --batch_size $BATCH_SIZE \ 21 | --replay_memory_size $REPLAY_MEMORY_SIZE \ 22 | # --load_checkpoint $LOAD_CHECKPOINT -------------------------------------------------------------------------------- /DeepReinforcementLearning/MadMario/environment.yml: -------------------------------------------------------------------------------- 1 | name: mario 2 | channels: 3 | - defaults 4 | dependencies: 5 | - ca-certificates=2020.1.1=0 6 | - certifi=2020.4.5.1=py38_0 7 | - libcxx 8 | - libedit=3.1.20181209 9 | - libffi=3.3 10 | - ncurses=6.2 11 | - openssl=1.1.1g 12 | - pip=20.0.2=py38_3 13 | - python=3.8.3 14 | - readline=8.0 15 | - setuptools=46.4.0=py38_0 16 | - sqlite=3.31.1 17 | - tk=8.6.8 18 | - wheel=0.34.2=py38_0 19 | - xz=5.2.5 20 | - zlib=1.2.11 21 | - pip: 22 | - cloudpickle==1.3.0 23 | - future==0.18.2 24 | - gym==0.17.2 25 | - gym-super-mario-bros==7.3.0 26 | - nes-py 27 | - numpy 28 | - opencv-python 29 | - pillow 30 | - pyglet 31 | - scipy 32 | - tqdm 33 | - python-dateutil 34 | - scikit-image 35 | prefix: /opt/anaconda3/envs/mario 36 | -------------------------------------------------------------------------------- /Demo/speaker_identification_demo/README.md: -------------------------------------------------------------------------------- 1 | # speaker recognization demo 2 | This is a demo of the speaker recognition question in the ZhejiangLab AI Voice Contest implementated with oneflow. 3 | 4 | 5 | ## Datasets: 6 | 7 | The demo data used here is the case where only two speakers are included. 8 | `data_preprocess.py` contains scripts to process the demo data into features compatible with Wav2Letter. 9 | Data preprocessing includes segmenting the voice according to the time period divided in the txt file, and generating the corresponding relationship between the voice segment and the speaker. 10 | 11 | ## Data preprocessed: 12 | 13 | ```bash 14 | sh data_preprocess.sh 15 | ``` 16 | 17 | ## Start training process: 18 | 19 | ```bash 20 | sh train.sh 21 | ``` 22 | 23 | ## Model inference, this one is configured to process `data/test_data/name1_15.wav` file. 24 | 25 | ```bash 26 | sh infer.sh 27 | ``` 28 | -------------------------------------------------------------------------------- /Demo/speaker_identification_demo/data_preprocess.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | DATA_DIR="data" 4 | DATA_PREPROCESSED_DIR="data_preprocessed" 5 | 6 | if [ ! -d "$DATA_DIR" ]; then 7 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/speaker_recognizatian_demo/data.zip 8 | unzip data.zip 9 | rm -fr data.zip 10 | fi 11 | 12 | if [ ! -d "$DATA_PREPROCESSED_DIR" ]; then 13 | mkdir $DATA_PREPROCESSED_DIR 14 | cd $DATA_PREPROCESSED_DIR 15 | touch label_dict.json 16 | mkdir train test && cd ../ 17 | fi 18 | 19 | python data_preprocess.py 20 | -------------------------------------------------------------------------------- /Demo/speaker_identification_demo/infer.sh: -------------------------------------------------------------------------------- 1 | python infer.py 2 | -------------------------------------------------------------------------------- /Demo/speaker_identification_demo/model/model.py: -------------------------------------------------------------------------------- 1 | import oneflow.nn as nn 2 | 3 | 4 | class simple_CNN(nn.Module): 5 | def __init__(self, num_speakers=2) -> None: 6 | super(simple_CNN, self).__init__() 7 | self.convs = nn.Sequential( 8 | nn.Conv1d(1, 16, 100, stride=10), 9 | nn.BatchNorm1d(16), 10 | nn.ReLU(), 11 | nn.Conv1d(16, 64, 21, stride=10), 12 | nn.BatchNorm1d(64), 13 | nn.ReLU(), 14 | nn.Conv1d(64, 64, 5, stride=5), 15 | nn.BatchNorm1d(64), 16 | nn.ReLU(), 17 | ) 18 | self.linears = nn.Sequential( 19 | nn.Linear(1 * 6 * 64, 128), nn.Linear(128, num_speakers) 20 | ) 21 | 22 | def forward(self, x): 23 | x = self.convs(x) 24 | x = x.view(x.size(0), -1) 25 | x = self.linears(x) 26 | 27 | return x 28 | -------------------------------------------------------------------------------- /Demo/speaker_identification_demo/train.sh: -------------------------------------------------------------------------------- 1 | python train.py 2 | -------------------------------------------------------------------------------- /GPT/oneflow_gpt/__init__.py: -------------------------------------------------------------------------------- 1 | MAJOR = 0 2 | MINOR = 0.2 3 | VERSION = (MAJOR, MINOR) 4 | 5 | __version__ = ".".join(map(str, VERSION)) 6 | __package_name__ = "oneflow_gpt" 7 | __description__ = "OneFlow GPT" 8 | __license__ = "" 9 | __keywords__ = "deep learning, Megatron, gpu, NLP, nvidia, cuda, oneflow" 10 | -------------------------------------------------------------------------------- /KnowledgeDistillation/KnowledgeDistillation/infer.sh: -------------------------------------------------------------------------------- 1 | python infer.py \ 2 | --model_type="student_kd" \ 3 | --model_load_dir="./output/model_save/student_kd" \ 4 | --image_save_name="./output/images/infer_result.jpg" \ 5 | --picture_index=9999 \ 6 | --temperature=10 -------------------------------------------------------------------------------- /KnowledgeDistillation/KnowledgeDistillation/requirements.txt: -------------------------------------------------------------------------------- 1 | flowvision==0.2.0 2 | matplotlib==3.4.3 3 | numpy==1.21.2 4 | -------------------------------------------------------------------------------- /KnowledgeDistillation/KnowledgeDistillation/train.sh: -------------------------------------------------------------------------------- 1 | 2 | python train.py \ 3 | --model_save_dir="./output/model_save" \ 4 | --image_save_name="./output/images/compare_result.jpg" \ 5 | --load_teacher_checkpoint_dir="./output/model_save/teacher" \ 6 | --model_type="compare"\ 7 | --epochs=10 \ 8 | --batch_size=128 \ 9 | --temperature=5.0 \ 10 | --alpha=0.7 \ 11 | 12 | 13 | -------------------------------------------------------------------------------- /KnowledgeDistillation/MetaKD/1_get_data.sh: -------------------------------------------------------------------------------- 1 | if [ ! -d ./data ];then 2 | mkdir data 3 | fi 4 | 5 | cd data 6 | if [ ! -f ./SENTI/dev.tsv ];then 7 | wget http://atp-modelzoo-sh.oss-cn-shanghai.aliyuncs.com/release/datasets/domain_sentiment_data.tar.gz 8 | tar -zxvf domain_sentiment_data.tar.gz 9 | fi 10 | 11 | cd .. 12 | if [ ! -f data/SENTI/dev.tsv ];then 13 | python generate_senti_data.py 14 | fi -------------------------------------------------------------------------------- /KnowledgeDistillation/MetaKD/2_process_data.sh: -------------------------------------------------------------------------------- 1 | if [ ! -f data/SENTI/train.embeddings.tsv ];then 2 | python extract_embeddings.py \ 3 | --bert_path "bert-base-uncased" \ 4 | --input data/SENTI/train.tsv \ 5 | --output data/SENTI/train.embeddings.tsv \ 6 | --task_name senti 7 | fi 8 | 9 | if [ ! -f data/SENTI/train_with_weights.tsv ];then 10 | python generate_meta_weights.py \ 11 | data/SENTI/train.embeddings.tsv \ 12 | data/SENTI/train_with_weights.tsv \ 13 | books,dvd,electronics,kitchen 14 | fi 15 | 16 | if [ ! -f data/SENTI/dev_standard.tsv ];then 17 | python generate_dev_file.py \ 18 | --input data/SENTI/dev.tsv \ 19 | --output data/SENTI/dev_standard.tsv 20 | fi -------------------------------------------------------------------------------- /KnowledgeDistillation/MetaKD/3_train_teacher.sh: -------------------------------------------------------------------------------- 1 | 2 | python meta_teacher_train.py \ 3 | --mode train \ 4 | --tables=data/SENTI/train_with_weights.tsv,data/SENTI/dev_standard.tsv \ 5 | --input_schema=guid:str:1,text_a:str:1,text_b:str:1,label:str:1,domain:str:1,weight:str:1 \ 6 | --first_sequence=text_a \ 7 | --second_sequence=text_b \ 8 | --label_name=label \ 9 | --label_enumerate_values=positive,negative \ 10 | --checkpoint_dir=./tmp/meta_teacher/ \ 11 | --learning_rate=3e-5 \ 12 | --epoch_num=5 \ 13 | --random_seed=42 \ 14 | --logging_steps=20 \ 15 | --save_checkpoint_steps=50 \ 16 | --sequence_length=128 \ 17 | --micro_batch_size=16 \ 18 | --app_name=text_classify \ 19 | --optimizer_type=AdamW \ 20 | --user_defined_parameters=" 21 | pretrain_model_name_or_path=bert-base-uncased 22 | pretrain_model_name_or_path_oneflow=bert-base-uncased-oneflow 23 | use_sample_weights=True 24 | use_domain_loss=True 25 | domain_loss_weight=0.5 26 | " 27 | -------------------------------------------------------------------------------- /KnowledgeDistillation/MetaKD/6_eval.sh: -------------------------------------------------------------------------------- 1 | # 3. Evalute 2 | Student_model_path=./tmp/books/meta_student_fintune 3 | python main_evaluate.py \ 4 | --mode evaluate \ 5 | --tables=data/SENTI/train_with_weights.tsv,data/SENTI/dev_standard.tsv \ 6 | --input_schema=guid:str:1,text_a:str:1,text_b:str:1,label:str:1,domain:str:1,weight:str:1 \ 7 | --first_sequence=text_a \ 8 | --label_name=label \ 9 | --label_enumerate_values=positive,negative \ 10 | --checkpoint_dir=./bert-tiny-uncased \ 11 | --learning_rate=3e-5 \ 12 | --epoch_num=1 \ 13 | --random_seed=42 \ 14 | --logging_steps=20 \ 15 | --sequence_length=128 \ 16 | --micro_batch_size=16 \ 17 | --app_name=text_classify \ 18 | --user_defined_parameters=" 19 | pretrain_model_name_or_path=$Student_model_path 20 | genre=$genre 21 | student_config_path=./bert-tiny-uncased-oneflow 22 | student_model_path=$Student_model_path 23 | " -------------------------------------------------------------------------------- /KnowledgeDistillation/MetaKD/easynlp/appzoo/sequence_classification/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright (c) 2020 Alibaba PAI team. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | -------------------------------------------------------------------------------- /KnowledgeDistillation/MetaKD/easynlp/distillation/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright (c) 2020 Alibaba PAI team. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | -------------------------------------------------------------------------------- /KnowledgeDistillation/MetaKD/easynlp/modelzoo/utils/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | # Copyright 2020. The Alibaba PAI Team. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | from packaging import version 18 | 19 | from .. import __version__ 20 | -------------------------------------------------------------------------------- /KnowledgeDistillation/MetaKD/easynlp/requirements.txt: -------------------------------------------------------------------------------- 1 | importlib_metadata == 4.7.0 2 | numpy == 1.21.2 3 | packaging == 21.0 4 | requests == 2.25.1 5 | scipy == 1.7.1 6 | sklearn == 0.0 7 | tqdm == 4.62.1 8 | -------------------------------------------------------------------------------- /KnowledgeDistillation/MetaKD/generate_dev_file.py: -------------------------------------------------------------------------------- 1 | import uuid 2 | import argparse 3 | 4 | 5 | if __name__ == "__main__": 6 | 7 | parser = argparse.ArgumentParser() 8 | parser.add_argument("--input", default=None, type=str) 9 | parser.add_argument("--output", default=None, type=str) 10 | 11 | args = parser.parse_args() 12 | 13 | with open(args.input, "r") as f: 14 | contents = f.readlines() 15 | with open(args.output, "w") as f: 16 | f.write( 17 | "\t".join(["guid", "text_a", "text_b", "label", "domain", "embeddings"]) 18 | + "\n" 19 | ) 20 | contents = contents[1:] 21 | for content in contents: 22 | line = content.strip().split("\t") 23 | new_line = "\t".join( 24 | [str(uuid.uuid4()), line[0], "", line[2], line[1], str(0)] 25 | ) 26 | f.write(new_line + "\n") 27 | -------------------------------------------------------------------------------- /KnowledgeDistillation/MetaKD/requirements.txt: -------------------------------------------------------------------------------- 1 | filelock 2 | tensorboardx 3 | datasets 4 | numpy==1.21.2 5 | pandas==1.3.2 6 | scikit_learn 7 | scipy==1.7.1 8 | tqdm==4.62.1 9 | transformers==4.21.2 10 | -------------------------------------------------------------------------------- /NLP/BERT/examples/infer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | MODEL_PATH="your convert model" 4 | 5 | export CUDA_VISIBLE_DEVICES=1 6 | python3 run_infer.py \ 7 | --use_lazy_model \ 8 | --model_path $MODEL_PATH 9 | -------------------------------------------------------------------------------- /NLP/BERT/examples/run_eager_pretrain.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | _DEVICE_NUM_PER_NODE=4 4 | _MASTER_ADDR=127.0.0.1 5 | _NUM_NODES=1 6 | _NODE_RANK=0 7 | 8 | _LR=0.02 9 | _BATCH_SIZE_PER_GPU=16 10 | train_data_dir=/dataset/bert/of_wiki_seq_len_128 11 | LOGFILE=./bert_graph_pretrain.log 12 | 13 | export PYTHONUNBUFFERED=1 14 | python3 -m oneflow.distributed.launch \ 15 | --nproc_per_node $_DEVICE_NUM_PER_NODE \ 16 | --nnodes $_NUM_NODES \ 17 | --node_rank $_NODE_RANK \ 18 | --master_addr $_MASTER_ADDR \ 19 | run_eager_pretraining.py \ 20 | --num_hidden_layers 12 \ 21 | --num_attention_heads 12 \ 22 | --max_position_embeddings 512 \ 23 | --seq_length 128 \ 24 | --vocab_size 30522 \ 25 | --type_vocab_size 2 \ 26 | --attention_probs_dropout_prob 0.1 \ 27 | --hidden_dropout_prob 0.1 \ 28 | --max_predictions_per_seq 20 \ 29 | --train-batch-size $_BATCH_SIZE_PER_GPU \ 30 | --lr $_LR \ 31 | --use_ddp \ 32 | --ofrecord_path $train_data_dir 2>&1 | tee ${LOGFILE} -------------------------------------------------------------------------------- /NLP/BERT/utils/checkpoint.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | import os 3 | from oneflow import nn 4 | 5 | 6 | def save_model( 7 | module: nn.Module, checkpoint_path: str, epoch: int, acc: float, is_consistent: bool 8 | ): 9 | state_dict = module.state_dict() 10 | save_path = os.path.join(checkpoint_path, "epoch_%d_val_acc_%f" % (epoch, acc)) 11 | if flow.env.get_rank() == 0: 12 | print(f"Saving model to {save_path}") 13 | if is_consistent: 14 | flow.save(state_dict, save_path, consistent_dst_rank=0) 15 | elif flow.env.get_rank() == 0: 16 | flow.save(state_dict, save_path) 17 | else: 18 | return 19 | -------------------------------------------------------------------------------- /NLP/BERT/utils/comm.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | 3 | 4 | def ttol(tensor, pure_local=True): 5 | """ to local """ 6 | if tensor.is_consistent: 7 | if pure_local: 8 | tensor = tensor.to_local() 9 | else: 10 | tensor = tensor.to_consistent(sbp=flow.sbp.broadcast).to_local() 11 | 12 | return tensor 13 | 14 | 15 | def tton(tensor, local_only=True): 16 | """ tensor to numpy """ 17 | if tensor.is_consistent: 18 | if local_only: 19 | tensor = tensor.to_local().numpy() 20 | else: 21 | tensor = tensor.to_consistent(sbp=flow.sbp.broadcast).to_local().numpy() 22 | else: 23 | tensor = tensor.numpy() 24 | 25 | return tensor 26 | -------------------------------------------------------------------------------- /NLP/CPT/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | LOAD_DIR="cpt_pretrain_afqmc" 4 | CPT_PRETRAIN_DIR='cpt-base' 5 | TASK="afqmc" 6 | TEXT1="订单退款成功了,为什么仍然要还花呗" 7 | TEXT2="退款到了花呗,为什么还要还款" 8 | 9 | if [ ! -d $LOAD_DIR ]; then 10 | echo "Please train CPT first." 11 | exit 12 | fi 13 | 14 | if [ ! -d $CPT_PRETRAIN_DIR ]; then 15 | echo "Downloading cpt-base." 16 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/nlp/CPT/cpt-base.tar.gz 17 | tar -xzf cpt-base.tar.gz 18 | fi 19 | 20 | python infer_flow.py \ 21 | --model_load_dir $LOAD_DIR \ 22 | --pretrain_dir $CPT_PRETRAIN_DIR \ 23 | --text1 $TEXT1 \ 24 | --text2 $TEXT2 \ 25 | --task $TASK \ 26 | --cuda 27 | 28 | -------------------------------------------------------------------------------- /NLP/CPT/models/utils.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | 3 | 4 | def gelu_new(x): 5 | gelu = flow.nn.GELU(approximate="tanh") 6 | return gelu(x) 7 | 8 | 9 | ACT2FN = { 10 | "relu": flow.nn.functional.relu, 11 | "gelu": flow.nn.functional.gelu, 12 | "tanh": flow.nn.functional.tanh, 13 | "gelu_new": gelu_new, 14 | "sigmoid": flow.nn.functional.sigmoid, 15 | } 16 | -------------------------------------------------------------------------------- /NLP/CPT/requirements.txt: -------------------------------------------------------------------------------- 1 | filelock==3.7.1 2 | huggingface_hub==0.8.1 3 | numpy==1.21.2 4 | packaging==21.0 5 | requests==2.25.1 6 | tqdm==4.62.1 7 | transformers==4.21.1 8 | -------------------------------------------------------------------------------- /NLP/CPT/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | LR=1e-5 4 | BATCH_SIZE=12 5 | LOAD_DIR="." 6 | SAVE_DIR="cpt_pretrain_afqmc" 7 | NEPOCHS=30 8 | CPT_PRETRAIN_DIR="cpt-base" 9 | TASK="afqmc" 10 | 11 | if [ ! -d $SAVE_DIR ]; then 12 | mkdir $SAVE_DIR 13 | fi 14 | 15 | if [ ! -d $CPT_PRETRAIN_DIR ]; then 16 | echo "Downloading cpt-base." 17 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/nlp/CPT/cpt-base.tar.gz 18 | tar -xzf cpt-base.tar.gz 19 | fi 20 | 21 | python train_flow.py \ 22 | --lr $LR \ 23 | --batch_size $BATCH_SIZE \ 24 | --n_epochs $NEPOCHS \ 25 | --model_load_dir $LOAD_DIR \ 26 | --model_save_dir $SAVE_DIR \ 27 | --pretrain_dir $CPT_PRETRAIN_DIR \ 28 | --task $TASK \ 29 | --cuda 30 | 31 | -------------------------------------------------------------------------------- /NLP/GPT2/finetune.sh: -------------------------------------------------------------------------------- 1 | #usr/bin/bash 2 | 3 | CUDA_VISIBLE_DEVICES=0 python train.py \ 4 | --train_dataset "data/corpus.small" \ 5 | --test_dataset "data/corpus.small" \ 6 | --vocab_file "gpt2-vocab.json" \ 7 | --merges_file "gpt2-merges.txt" \ 8 | --output_path "outputs" \ 9 | --restore_file "gpt2_oneflow_model" \ 10 | --seq_len 128 \ 11 | --batch_size 4 \ 12 | --epochs 20 \ 13 | --num_workers 1 \ 14 | --lr 3e-4 \ 15 | --adam_weight_decay 0.01 \ 16 | --adam_beta1 0.98 \ 17 | --adam_beta2 0.999 \ 18 | --warmup_steps 0 \ 19 | --accumulate_gradient_steps 1; -------------------------------------------------------------------------------- /NLP/GPT2/infer.sh: -------------------------------------------------------------------------------- 1 | 2 | python run_generation.py --restore_file "gpt2_oneflow_model" --top_k 1 -------------------------------------------------------------------------------- /NLP/GPT2/requirements.txt: -------------------------------------------------------------------------------- 1 | transformers==4.9.2 2 | numpy==1.20.1 3 | tqdm==4.62.2 4 | regex==2021.8.28 5 | torch==1.7.1 6 | six==1.16.0 7 | matplotlib==3.4.3 8 | file_utils==0.0.1 9 | pandas==1.3.3 10 | sample==1.0.0 11 | utils==1.0.1 12 | -------------------------------------------------------------------------------- /NLP/GPT2/tokenizer/__init__.py: -------------------------------------------------------------------------------- 1 | from .tokenizer import build_tokenizer 2 | -------------------------------------------------------------------------------- /NLP/GPT2/train.sh: -------------------------------------------------------------------------------- 1 | #usr/bin/bash 2 | 3 | CUDA_VISIBLE_DEVICES=0 python train.py \ 4 | --train_dataset "data/corpus.small" \ 5 | --test_dataset "data/corpus.small" \ 6 | --vocab_file "gpt2-vocab.json" \ 7 | --merges_file "gpt2-merges.txt" \ 8 | --output_path "outputs" \ 9 | --seq_len 128 \ 10 | --batch_size 4 \ 11 | --epochs 20 \ 12 | --num_workers 1 \ 13 | --lr 3e-4 \ 14 | --adam_weight_decay 0.01 \ 15 | --adam_beta1 0.98 \ 16 | --adam_beta2 0.999 \ 17 | --warmup_steps 0 \ 18 | --accumulate_gradient_steps 1; -------------------------------------------------------------------------------- /NLP/LSTMText/README.md: -------------------------------------------------------------------------------- 1 | # TextBiLSTM 2 | 3 | This repo is based on https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/rnn.py. 4 | 5 | ## Training on IMDb dataset 6 | 7 | ### Preparing IMDb dataset 8 | 9 | ```bash 10 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/models/Imdb_ofrecord.tar.gz 11 | tar zxf Imdb_ofrecord.tar.gz 12 | ``` 13 | 14 | ### Train 15 | 16 | ```bash 17 | bash train.sh 18 | ``` 19 | 20 | Note that the parameters of the provided pre-trained model is : 21 | 22 | ```bash 23 | BATCH_SIZE=32 24 | EPOCH=30 25 | LEARNING_RATE=3e-4 26 | SEQUENCE_LEN=128 27 | EMBEDDING_DIM=100 28 | NFC=128 29 | HIDDEN_SIZE=256 30 | ``` 31 | 32 | ## Inference on Single Text 33 | ```bash 34 | bash infer.sh 35 | ``` 36 | 37 | The example text is a simple sentence `"It is awesome! It is nice. The director does a good job!"` (or `"The film is digusting!"`). You can change this text in `infer.sh`. -------------------------------------------------------------------------------- /NLP/LSTMText/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | SEQUENCE_LEN=128 4 | EMBEDDING_DIM=100 5 | HIDDEN_SIZE=256 6 | 7 | LOAD_DIR="pretrain_model" 8 | IMDB_PATH="./imdb" 9 | TEXT="It is awesome! It is nice. The director does a good job!" 10 | 11 | if [ ! -d "$LOAD_DIR" ]; then 12 | echo "Directory '$LOAD_DIR' doesn't exist." 13 | echo "Please train the model first or download pretrained model." 14 | exit 1 15 | fi 16 | 17 | if [ ! -d "$IMDB_PATH" ]; then 18 | echo "Directory '$IMDB_PATH' doesn't exist." 19 | echo "Please set the correct path of imdb dataset." 20 | exit 1 21 | fi 22 | 23 | python3 infer.py \ 24 | --sequence_length $SEQUENCE_LEN \ 25 | --emb_dim $EMBEDDING_DIM \ 26 | --hidden_size $HIDDEN_SIZE \ 27 | --model_load_dir $LOAD_DIR \ 28 | --imdb_path $IMDB_PATH \ 29 | --text "$TEXT" 30 | -------------------------------------------------------------------------------- /NLP/LSTMText/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | six 3 | shutil -------------------------------------------------------------------------------- /NLP/LSTMText/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | MODEL_PATH="pretrain_model" 4 | if [ ! -d "$MODEL_PATH" ]; then 5 | mkdir $MODEL_PATH 6 | fi 7 | 8 | BATCH_SIZE=32 9 | EPOCH=30 10 | LEARNING_RATE=3e-4 11 | SEQUENCE_LEN=128 12 | EMBEDDING_DIM=100 13 | HIDDEN_SIZE=256 14 | 15 | SAVE_EVERY_EPOCHS=1 16 | LOAD_DIR="." 17 | SAVE_DIR="pretrain_model" 18 | IMDB_PATH="./imdb" 19 | 20 | 21 | python3 train_bilstm.py \ 22 | --batch_size $BATCH_SIZE \ 23 | --n_epochs $EPOCH \ 24 | --lr $LEARNING_RATE \ 25 | --sequence_length $SEQUENCE_LEN \ 26 | --emb_dim $EMBEDDING_DIM \ 27 | --hidden_size $HIDDEN_SIZE \ 28 | --model_load_dir $LOAD_DIR \ 29 | --model_save_every_n_epochs $SAVE_EVERY_EPOCHS \ 30 | --model_save_dir $SAVE_DIR \ 31 | --imdb_path "$IMDB_PATH" 32 | -------------------------------------------------------------------------------- /NLP/LSTMText/utils.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | sys.path.append("../") 4 | from imdb.utils import * 5 | 6 | 7 | __all__ = ["pad_sequences", "load_imdb_data", "colored_string"] 8 | -------------------------------------------------------------------------------- /NLP/MoE/README.md: -------------------------------------------------------------------------------- 1 | # The Sparsely Gated Mixture of Experts Layer for Oneflow 2 | 3 | 4 | 5 | ![source: https://techburst.io/outrageously-large-neural-network-gated-mixture-of-experts-billions-of-parameter-same-d3e901f2fe05](https://miro.medium.com/max/1000/1*AaBzgpJcySeO1UDvOQ_CnQ.png) 6 | 7 | 8 | This repository contains the Oneflow re-implementation of the sparsely-gated MoE layer described in the paper [Outrageously Large Neural Networks](https://arxiv.org/abs/1701.06538) for PyTorch. 9 | 10 | # Usage 11 | 12 | 13 | 14 | ```python 15 | 16 | # k indicates the top-k switching 17 | model = MoE(expert_network, input_size, output_size, num_experts, noisy_gating, k) 18 | 19 | 20 | ``` 21 | 22 | 23 | 24 | 25 | # Citing 26 | ``` 27 | @misc{rau2019moe, 28 | title={Sparsely-gated Mixture-of-Experts PyTorch implementation}, 29 | author={Rau, David}, 30 | journal={https://github.com/davidmrau/mixture-of-experts}, 31 | year={2019} 32 | } 33 | ``` 34 | 35 | -------------------------------------------------------------------------------- /NLP/MoE/mlp.py: -------------------------------------------------------------------------------- 1 | import oneflow.nn as nn 2 | 3 | 4 | class MLP(nn.Module): 5 | def __init__(self, input_size, output_size, hidden_size): 6 | super(MLP, self).__init__() 7 | self.fc1 = nn.Linear(input_size, hidden_size) 8 | self.fc2 = nn.Linear(hidden_size, output_size) 9 | self.relu = nn.ReLU() 10 | self.log_soft = nn.LogSoftmax(1) 11 | 12 | def forward(self, x): 13 | out = self.fc1(x) 14 | out = self.relu(out) 15 | out = self.fc2(out) 16 | out = self.log_soft(out) 17 | return out 18 | -------------------------------------------------------------------------------- /NLP/MoE/requirements.txt: -------------------------------------------------------------------------------- 1 | flowvision==0.0.3 2 | -------------------------------------------------------------------------------- /NLP/MoE/train.sh: -------------------------------------------------------------------------------- 1 | LEARNING_RATE=0.001 2 | MOM=0.9 3 | EPOCH=10 4 | TRAIN_BATCH_SIZE=64 5 | VAL_BATCH_SIZE=64 6 | 7 | 8 | python3 cifar10_example.py \ 9 | --learning_rate $LEARNING_RATE \ 10 | --mom $MOM \ 11 | --epochs $EPOCH \ 12 | --train_batch_size $TRAIN_BATCH_SIZE \ 13 | --val_batch_size $VAL_BATCH_SIZE \ 14 | -------------------------------------------------------------------------------- /NLP/TextCNN/README.md: -------------------------------------------------------------------------------- 1 | # TextCNN 2 | 3 | TextCNN is a Text Classification model, our code is inspired by [Pytorch-TextCNN](https://github.com/leohsuofnthu/Pytorch-TextCNN). 4 | 5 | 6 | ## Train on [imdb](https://www.imdb.com/interfaces/) Dataset 7 | ### Run Oneflow Training script 8 | 9 | ```bash 10 | bash train.sh 11 | ``` 12 | 13 | ## Inference 14 | ### Run Oneflow Inference script 15 | 16 | ```bash 17 | bash infer.sh 18 | ``` 19 | -------------------------------------------------------------------------------- /NLP/TextCNN/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | MODEL_PATH="checkpoints" 4 | VOCAB_PATH="vocab.pkl" 5 | CONFIG_PATH="config.json" 6 | TEXT="My boyfriend and I went to watch The Guardian.At first I didn't want to watch it, but I loved the movie- It was definitely the best movie I have seen in sometime.They portrayed the USCG very well, it really showed me what they do and I think they should really be appreciated more.Not only did it teach but it was a really good movie. The movie shows what the really do and how hard the job is.I think being a USCG would be challenging and very scary. It was a great movie all around. I would suggest this movie for anyone to see.The ending broke my heart but I know why he did it. The storyline was great I give it 2 thumbs up. I cried it was very emotional, I would give it a 20 if I could!" 7 | 8 | python3 infer.py --model_path $MODEL_PATH --vocab_path $VOCAB_PATH --config_path $CONFIG_PATH --text "$TEXT" 9 | -------------------------------------------------------------------------------- /NLP/TextCNN/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | tqdm 3 | spacy 4 | python -m spacy download en_core_web_sm -------------------------------------------------------------------------------- /NLP/TextCNN/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | IMDB_PATH="aclImdb" 4 | if [ ! -d "$IMDB_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/aclImdb_v1.tar.gz 6 | tar zxf aclImdb_v1.tar.gz 7 | fi 8 | 9 | LEARNING_RATE=0.001 10 | EPOCH=15 11 | TRAIN_BATCH_SIZE=16 12 | VAL_BATCH_SIZE=16 13 | CHECKPOINT_PATH="checkpoints" 14 | 15 | python3 train_of_textcnn.py \ 16 | --save_checkpoint_path $CHECKPOINT_PATH \ 17 | --learning_rate $LEARNING_RATE \ 18 | --epochs $EPOCH \ 19 | --train_batch_size $TRAIN_BATCH_SIZE \ 20 | --val_batch_size $VAL_BATCH_SIZE \ 21 | --kernel_size 3 4 5 -------------------------------------------------------------------------------- /NLP/Transformer/imdb/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | SEQUENCE_LEN=128 4 | VOCAB_SZ=100000 5 | D_MODEL=512 6 | DROPOUT=0.1 7 | NHEAD=8 8 | NUM_LAYERS=4 9 | DIM_FF=1024 10 | LOAD_DIR="best_model" 11 | IMDB_PATH="../datasets/imdb" 12 | TEXT="It is awesome! It is nice. The director does a good job!" 13 | 14 | if [ ! -d "$LOAD_DIR" ]; then 15 | echo "Directory '$LOAD_DIR' doesn't exist." 16 | echo "Please train the model first or download pretrained model." 17 | exit 1 18 | fi 19 | 20 | python3 infer_transformer_imdb.py \ 21 | --sequence_len $SEQUENCE_LEN \ 22 | --vocab_sz $VOCAB_SZ \ 23 | --d_model $D_MODEL \ 24 | --dropout $DROPOUT \ 25 | --n_head $NHEAD \ 26 | --n_encoder_layers $NUM_LAYERS \ 27 | --dim_feedforward $DIM_FF \ 28 | --load_dir $LOAD_DIR \ 29 | --imdb_path "$IMDB_PATH" \ 30 | --text "$TEXT" -------------------------------------------------------------------------------- /NLP/Transformer/imdb/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | MODEL_PATH="best_model" 4 | if [ ! -d "$MODEL_PATH" ]; then 5 | mkdir $MODEL_PATH 6 | fi 7 | 8 | BATCH_SIZE=32 9 | EPOCH=15 10 | LEARNING_RATE=0.0001 11 | 12 | SEQUENCE_LEN=128 13 | VOCAB_SZ=100000 14 | D_MODEL=512 15 | DROPOUT=0.1 16 | NHEAD=8 17 | NUM_LAYERS=4 18 | DIM_FF=1024 19 | 20 | IMDB_PATH="../datasets/imdb" 21 | LOAD_DIR="." 22 | SAVE_DIR="best_model" 23 | 24 | python3 train_transformer_imdb.py \ 25 | --batch_size $BATCH_SIZE \ 26 | --n_epochs $EPOCH \ 27 | --lr $LEARNING_RATE \ 28 | --sequence_len $SEQUENCE_LEN \ 29 | --vocab_sz $VOCAB_SZ \ 30 | --d_model $D_MODEL \ 31 | --dropout $DROPOUT \ 32 | --n_head $NHEAD \ 33 | --n_encoder_layers $NUM_LAYERS \ 34 | --dim_feedforward $DIM_FF \ 35 | --imdb_path "$IMDB_PATH" \ 36 | --load_dir $LOAD_DIR \ 37 | --save_dir $SAVE_DIR -------------------------------------------------------------------------------- /NLP/Transformer/imdb/utils.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | sys.path.append("../datasets/") 4 | from imdb.utils import pad_sequences, load_imdb_data, colored_string 5 | 6 | __all__ = ["pad_sequences", "load_imdb_data", "colored_string"] 7 | -------------------------------------------------------------------------------- /NLP/Transformer/odd_numbers/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | VOCAB_SZ=10000 4 | D_MODEL=512 5 | DROPOUT=0.0 6 | NHEAD=2 7 | NUM_ENCODER_LAYERS=1 8 | NUM_DECODER_LAYERS=1 9 | DIM_FF=128 10 | 11 | LOAD_DIR="best_model" 12 | INPUT_START=4386 13 | 14 | if [ ! -d "$LOAD_DIR" ]; then 15 | echo "Directory '$LOAD_DIR' doesn't exist." 16 | echo "Please train the model first or download pretrained model." 17 | exit 1 18 | fi 19 | 20 | python3 infer_transformer_odd_numbers.py \ 21 | --vocab_sz $VOCAB_SZ \ 22 | --d_model $D_MODEL \ 23 | --dropout $DROPOUT \ 24 | --n_head $NHEAD \ 25 | --n_encoder_layers $NUM_ENCODER_LAYERS \ 26 | --n_decoder_layers $NUM_DECODER_LAYERS \ 27 | --dim_feedforward $DIM_FF \ 28 | --load_dir $LOAD_DIR \ 29 | --input_start $INPUT_START 30 | -------------------------------------------------------------------------------- /NLP/Transformer/odd_numbers/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | MODEL_PATH="best_model" 4 | if [ ! -d "$MODEL_PATH" ]; then 5 | mkdir $MODEL_PATH 6 | fi 7 | 8 | BATCH_SIZE=128 9 | EPOCH=30 10 | LEARNING_RATE=0.0001 11 | 12 | VOCAB_SZ=10000 13 | D_MODEL=512 14 | DROPOUT=0.0 15 | NHEAD=2 16 | NUM_ENCODER_LAYERS=1 17 | NUM_DECODER_LAYERS=1 18 | DIM_FF=128 19 | 20 | LOAD_DIR="." 21 | SAVE_DIR="best_model" 22 | 23 | python3 train_transformer_odd_numbers.py \ 24 | --batch_size $BATCH_SIZE \ 25 | --n_epochs $EPOCH \ 26 | --lr $LEARNING_RATE \ 27 | --vocab_sz $VOCAB_SZ \ 28 | --d_model $D_MODEL \ 29 | --dropout $DROPOUT \ 30 | --n_head $NHEAD \ 31 | --n_encoder_layers $NUM_ENCODER_LAYERS \ 32 | --n_decoder_layers $NUM_DECODER_LAYERS \ 33 | --dim_feedforward $DIM_FF \ 34 | --load_dir $LOAD_DIR \ 35 | --save_dir $SAVE_DIR 36 | -------------------------------------------------------------------------------- /NLP/Transformer/transformer/__init__.py: -------------------------------------------------------------------------------- 1 | from .transformer import ( 2 | Transformer, 3 | TransformerDecoder, 4 | TransformerEncoder, 5 | TransformerDecoderLayer, 6 | TransformerEncoderLayer, 7 | ) 8 | 9 | __all__ = [ 10 | "Transformer", 11 | "TransformerDecoder", 12 | "TransformerEncoder", 13 | "TransformerDecoderLayer", 14 | "TransformerEncoderLayer", 15 | ] 16 | -------------------------------------------------------------------------------- /NLP/rnn/README.md: -------------------------------------------------------------------------------- 1 | refers to: https://pytorch.org/tutorials/intermediate/char_rnn_classification_tutorial.html 2 | 3 | ## run rnn predict demo 4 | ```bash 5 | python3 predict.py 6 | ``` 7 | 8 | ## run rnn train demo and speed comparison demo 9 | 10 | ``` 11 | bash train.sh 12 | ``` 13 | 14 | See comment in train.sh for running lstm train demo and speed comparison demo. -------------------------------------------------------------------------------- /NLP/rnn/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/NLP/rnn/models/__init__.py -------------------------------------------------------------------------------- /NLP/rnn/models/rnn_model.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | import oneflow.nn as nn 3 | 4 | 5 | class RNN(nn.Module): 6 | def __init__(self, input_size, hidden_size, output_size): 7 | super().__init__() 8 | 9 | self.hidden_size = hidden_size 10 | 11 | self.i2h = nn.Linear(input_size + hidden_size, hidden_size) 12 | self.i2o = nn.Linear(input_size + hidden_size, output_size) 13 | self.softmax = nn.LogSoftmax(dim=1) 14 | 15 | def forward(self, input, hidden): 16 | combined = flow.cat([input, hidden], dim=1) 17 | hidden = self.i2h(combined) 18 | output = self.i2o(combined) 19 | output = self.softmax(output) 20 | return output, hidden 21 | 22 | def initHidden(self): 23 | hidden = flow.Tensor(1, self.hidden_size) 24 | flow.nn.init.zeros_(hidden) 25 | return hidden.to("cuda") 26 | -------------------------------------------------------------------------------- /NLP/rnn/models/rnn_model_pytorch.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | import torch 3 | import random 4 | import math 5 | 6 | 7 | class RNN_PYTORCH(nn.Module): 8 | def __init__(self, input_size, hidden_size, output_size): 9 | super(RNN_PYTORCH, self).__init__() 10 | 11 | self.hidden_size = hidden_size 12 | 13 | self.i2h = nn.Linear(input_size + hidden_size, hidden_size) 14 | self.i2o = nn.Linear(input_size + hidden_size, output_size) 15 | self.softmax = nn.LogSoftmax(dim=1) 16 | 17 | def forward(self, input, hidden): 18 | combined = torch.cat((input, hidden), 1).to("cuda") 19 | hidden = self.i2h(combined) 20 | output = self.i2o(combined) 21 | output = self.softmax(output) 22 | return output, hidden 23 | 24 | def initHidden(self): 25 | return torch.zeros(1, self.hidden_size).to("cuda") 26 | -------------------------------------------------------------------------------- /NLP/rnn/predict.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | 3 | from utils.dataset import * 4 | from utils.tensor_utils import * 5 | from models.rnn_model import RNN 6 | 7 | 8 | dataset_path = "./data/names" 9 | n_categories = processDataset(dataset_path) 10 | print(letterToTensor("J")) 11 | print(lineToTensor("Jones").size()) 12 | for i in range(10): 13 | category, line, category_tensor, line_tensor = randomTrainingExample() 14 | print("category =", category, "/ line =", line, line_tensor.shape) 15 | 16 | n_hidden = 128 17 | rnn = RNN(n_letters, n_hidden, n_categories) 18 | rnn.to("cuda") 19 | 20 | input = lineToTensor("Albert") 21 | # NOTE(Liang Depeng): original torch implementation 22 | # hidden = torch.zeros(1, n_hidden) 23 | hidden = flow.Tensor(1, n_hidden, device="cuda") 24 | flow.nn.init.ones_(hidden) 25 | print(input) 26 | print(input[0]) 27 | output, next_hidden = rnn(input[0], hidden) 28 | print(output.numpy()) 29 | -------------------------------------------------------------------------------- /NLP/rnn/requirements.txt: -------------------------------------------------------------------------------- 1 | torch 2 | numpy 3 | -------------------------------------------------------------------------------- /NLP/rnn/train.sh: -------------------------------------------------------------------------------- 1 | model="lstm" # choose between rnn and lstm 2 | 3 | if [ ! -d "data/" ]; then 4 | wget https://download.pytorch.org/tutorial/data.zip 5 | unzip data.zip 6 | fi 7 | 8 | echo "begin ${model} speed comparison demo" 9 | 10 | python3 compare_oneflow_and_pytorch_${model}_speed.py 11 | 12 | echo "begin ${model} training demo" 13 | 14 | python3 train_${model}_oneflow.py -------------------------------------------------------------------------------- /NLP/rnn/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/NLP/rnn/utils/__init__.py -------------------------------------------------------------------------------- /NLP/roberta/config.py: -------------------------------------------------------------------------------- 1 | def infer_config(args): 2 | if args.task == "SST-2": 3 | args.n_classes = 2 4 | args.roberta_hidden_size = 768 5 | args.is_train = False 6 | elif args.task == "MNLI": 7 | args.n_classes = 3 8 | args.roberta_hidden_size = 768 9 | args.is_train = False 10 | 11 | 12 | def train_config(args): 13 | if args.task == "SST-2": 14 | args.n_classes = 2 15 | args.roberta_hidden_size = 768 16 | args.is_train = True 17 | elif args.task == "MNLI": 18 | args.n_classes = 3 19 | args.roberta_hidden_size = 768 20 | args.is_train = True 21 | -------------------------------------------------------------------------------- /NLP/roberta/infer_MNLI.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_DIR="./roberta-base-oneflow/weights" 4 | KWARGS_PATH="./roberta-base-oneflow/parameters.json" 5 | MODEL_LOAD_DIR="./pretrain_model_MNLI" 6 | TEXT="The new rights are nice enough. Everyone really likes the newest benefits." 7 | TASK="MNLI" 8 | # YOU CAN CHANGE THE 'TEXT' AS YOU WISH, SUCH AS / 9 | # "mark me down as a non-believer in werewolf films that are not serious and rely on 10 | # stupidity as a substitute for humor ." 11 | # "most new movies have a bright sheen ." 12 | 13 | if [ ! -d "$MODEL_LOAD_DIR" ]; then 14 | echo "Directory '$MODEL_LOAD_DIR' doesn't exist." 15 | echo "Please train the model first or download pretrained model." 16 | exit 1 17 | fi 18 | 19 | python3 infer_MNLI.py \ 20 | --pretrain_dir $PRETRAIN_DIR\ 21 | --kwargs_path $KWARGS_PATH\ 22 | --model_load_dir $MODEL_LOAD_DIR \ 23 | --text "$TEXT" \ 24 | --task $TASK -------------------------------------------------------------------------------- /NLP/roberta/infer_SST2.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | PRETRAIN_DIR="./roberta-base-oneflow/weights" 5 | KWARGS_PATH="./roberta-base-oneflow/parameters.json" 6 | MODEL_LOAD_DIR="./pretrain_model_SST-2" 7 | TEXT="this is junk food cinema at its greasiest ." 8 | TASK="SST-2" 9 | # YOU CAN CHANGE THE 'TEXT' AS YOU WISH, SUCH AS / 10 | #"mark me down as a non-believer in werewolf films that are not serious and rely on stupidity as a substitute for humor ." 11 | #"most new movies have a bright sheen ." 12 | 13 | if [ ! -d "$MODEL_LOAD_DIR" ]; then 14 | echo "Directory '$MODEL_LOAD_DIR' doesn't exist." 15 | echo "Please train the model first or download pretrained model." 16 | exit 1 17 | fi 18 | 19 | python3 infer_SST2.py \ 20 | --pretrain_dir $PRETRAIN_DIR\ 21 | --kwargs_path $KWARGS_PATH\ 22 | --model_load_dir $MODEL_LOAD_DIR \ 23 | --text "$TEXT" \ 24 | --task $TASK -------------------------------------------------------------------------------- /NLP/roberta/requirements.txt: -------------------------------------------------------------------------------- 1 | filelock==3.7.1 2 | huggingface_hub==0.8.1 3 | numpy==1.21.2 4 | packaging==21.0 5 | regex==2021.8.21 6 | requests==2.25.1 7 | tqdm==4.62.1 8 | transformers==4.21.1 9 | 10 | -------------------------------------------------------------------------------- /NLP/roberta/train_MNLI.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | BATCH_SIZE=32 4 | EPOCH=20 5 | LEARNING_RATE=1e-5 6 | PRETRAIN_DIR="./roberta-base-oneflow/weights" 7 | KWARGS_PATH="./roberta-base-oneflow/parameters.json" 8 | SAVE_DIR="./pretrain_model_MNLI" 9 | TASK="MNLI" 10 | 11 | if [ ! -d $SAVE_DIR ]; then 12 | mkdir $SAVE_DIR 13 | fi 14 | 15 | python3 train_MNLI.py \ 16 | --batch_size $BATCH_SIZE \ 17 | --n_epochs $EPOCH \ 18 | --lr $LEARNING_RATE \ 19 | --pretrain_dir $PRETRAIN_DIR\ 20 | --kwargs_path $KWARGS_PATH\ 21 | --model_save_dir $SAVE_DIR\ 22 | --task $TASK -------------------------------------------------------------------------------- /NLP/roberta/train_SST2.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | BATCH_SIZE=32 4 | EPOCH=20 5 | LEARNING_RATE=1e-5 6 | PRETRAIN_DIR="./roberta-base-oneflow/weights" 7 | KWARGS_PATH="./roberta-base-oneflow/parameters.json" 8 | SAVE_DIR="./pretrain_model_SST-2" 9 | TASK="SST-2" 10 | 11 | if [ ! -d $SAVE_DIR ]; then 12 | mkdir $SAVE_DIR 13 | fi 14 | 15 | python3 train_SST2.py \ 16 | --batch_size $BATCH_SIZE \ 17 | --n_epochs $EPOCH \ 18 | --lr $LEARNING_RATE \ 19 | --pretrain_dir $PRETRAIN_DIR\ 20 | --kwargs_path $KWARGS_PATH\ 21 | --model_save_dir $SAVE_DIR\ 22 | --task $TASK -------------------------------------------------------------------------------- /NLP/seq2seq/README.md: -------------------------------------------------------------------------------- 1 | # seq2seq for translation 2 | 3 | This repo is based on https://pytorch.org/tutorials/intermediate/seq2seq_translation_tutorial.html 4 | 5 | ### Eval 6 | 7 | ```bash 8 | bash eval_oneflow.sh 9 | ``` 10 | 11 | ### Train 12 | 13 | ```bash 14 | bash train_oneflow.sh 15 | ``` 16 | -------------------------------------------------------------------------------- /NLP/seq2seq/eval_oneflow.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | DATA_PATH="data" 4 | if [ ! -d "$DATA_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/seq2seq_data.tar.gz 6 | tar -xzvf seq2seq_data.tar.gz 7 | fi 8 | 9 | PRETRAIN_PATH="saving_model_oneflow" 10 | if [ ! -d "$PRETRAIN_PATH" ]; then 11 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/nlp/seq2seq_pre_train.tar.gz 12 | tar -xzvf seq2seq_pre_train.tar.gz 13 | fi 14 | 15 | ENCODER_PATH="./saving_model_oneflow/encoder/" 16 | DECODER_PATH="./saving_model_oneflow/decoder/" 17 | 18 | DEVICE='cuda' 19 | 20 | python3 eval_oneflow.py \ 21 | --encoder_path $ENCODER_PATH \ 22 | --decoder_path $DECODER_PATH \ 23 | --device $DEVICE -------------------------------------------------------------------------------- /NLP/seq2seq/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/NLP/seq2seq/models/__init__.py -------------------------------------------------------------------------------- /NLP/seq2seq/requirements.txt: -------------------------------------------------------------------------------- 1 | matplotlib 2 | numpy -------------------------------------------------------------------------------- /NLP/seq2seq/train_oneflow.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | DATA_PATH="data" 5 | if [ ! -d "$DATA_PATH" ]; then 6 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/seq2seq_data.tar.gz 7 | tar -xzvf seq2seq_data.tar.gz 8 | fi 9 | 10 | DEVICE='cuda' 11 | SAVE_ENCODER_CHECKPOINT_PATH="./saving_model_oneflow/encoder/" 12 | SAVE_DECODER_CHECKPOINT_PATH="./saving_model_oneflow/decoder/" 13 | HIDDDEN_SIZE=256 14 | N_ITERS=75000 15 | LR=0.01 16 | DROP=0.1 17 | 18 | 19 | python3 train_oneflow.py \ 20 | --device $DEVICE \ 21 | --save_encoder_checkpoint_path $SAVE_ENCODER_CHECKPOINT_PATH \ 22 | --save_decoder_checkpoint_path $SAVE_DECODER_CHECKPOINT_PATH \ 23 | --hidden_size $HIDDDEN_SIZE \ 24 | --n_iters $N_ITERS \ 25 | --lr $LR \ 26 | --drop $DROP -------------------------------------------------------------------------------- /NLP/seq2seq/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/NLP/seq2seq/utils/__init__.py -------------------------------------------------------------------------------- /Quantization/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Quantization/__init__.py -------------------------------------------------------------------------------- /Quantization/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="./checkpoints/epoch_19_val_acc_0.732143" 4 | IMAGE_PATH="imagenette2/val/n01440764/ILSVRC2012_val_00009111.JPEG" 5 | QUANTIZATION_BIT=8 6 | QUANTIZATION_SCHEME="symmetric" 7 | QUANTIZATION_FORMULA="google" 8 | PER_LAYER_QUANTIZATION=True 9 | 10 | 11 | if [ ! -d "data" ]; then 12 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 13 | tar zxf data.tar.gz 14 | fi 15 | 16 | python3 quantization_infer.py \ 17 | --model_path $PRETRAIN_MODEL_PATH\ 18 | --image_path $IMAGE_PATH\ 19 | --quantization_bit $QUANTIZATION_BIT \ 20 | --quantization_scheme $QUANTIZATION_SCHEME \ 21 | --quantization_formula $QUANTIZATION_FORMULA \ 22 | --per_layer_quantization $PER_LAYER_QUANTIZATION 23 | -------------------------------------------------------------------------------- /Quantization/quantization_ops/__init__.py: -------------------------------------------------------------------------------- 1 | from quantization_ops.conv import QConv2d as q_conv 2 | from quantization_ops.linear import QLinear as q_linear 3 | from quantization_ops.conv_bn import QConvBN as q_conv_bn 4 | -------------------------------------------------------------------------------- /Quantization/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Quantization/utils/__init__.py -------------------------------------------------------------------------------- /Quantization/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /RecommenderSystems/dcn/eager_train.sh: -------------------------------------------------------------------------------- 1 | DEVICE_NUM_PER_NODE=1 2 | DATA_DIR=your_path/criteo_parquet 3 | PERSISTENT_PATH=your_path/persistent1 4 | MODEL_SAVE_DIR=your_path/model_save_dir 5 | 6 | python3 -m oneflow.distributed.launch \ 7 | --nproc_per_node $DEVICE_NUM_PER_NODE \ 8 | --nnodes 1 \ 9 | --node_rank 0 \ 10 | --master_addr 127.0.0.1 \ 11 | dcn_eager_train_eval.py \ 12 | --data_dir $DATA_DIR \ 13 | --model_save_dir $MODEL_SAVE_DIR \ 14 | --persistent_path $PERSISTENT_PATH \ 15 | --table_size_array "649,9364,14746,490,476707,11618,4142,1373,7275,13,169,407,1376,1460,583,10131227,2202608,305,24,12517,633,3,93145,5683,8351593,3194,27,14992,5461306,10,5652,2173,4,7046547,18,15,286181,105,142572" \ 16 | --store_type 'cached_host_mem' \ 17 | --cache_memory_budget_mb 2048 \ 18 | --dnn_hidden_units "1000, 1000, 1000, 1000, 1000" \ 19 | --crossing_layers 4 \ 20 | --embedding_vec_size 16 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /RecommenderSystems/dcn/requirements.txt: -------------------------------------------------------------------------------- 1 | petastorm 2 | psutil 3 | pandas 4 | sklearn 5 | 6 | 7 | -------------------------------------------------------------------------------- /RecommenderSystems/dcn/tools/launch_spark.sh: -------------------------------------------------------------------------------- 1 | export SPARK_LOCAL_DIRS=/tmp/tmp_spark 2 | spark-shell \ 3 | --master "local[*]" \ 4 | --conf spark.driver.maxResultSize=0 \ 5 | --driver-memory 360G 6 | 7 | -------------------------------------------------------------------------------- /RecommenderSystems/dcn/train.sh: -------------------------------------------------------------------------------- 1 | DEVICE_NUM_PER_NODE=1 2 | DATA_DIR=your_path/criteo_parquet 3 | PERSISTENT_PATH=your_path/persistent1 4 | MODEL_SAVE_DIR=your_path/model_save_dir 5 | 6 | python3 -m oneflow.distributed.launch \ 7 | --nproc_per_node $DEVICE_NUM_PER_NODE \ 8 | --nnodes 1 \ 9 | --node_rank 0 \ 10 | --master_addr 127.0.0.1 \ 11 | dcn_train_eval.py \ 12 | --data_dir $DATA_DIR \ 13 | --model_save_dir $MODEL_SAVE_DIR \ 14 | --persistent_path $PERSISTENT_PATH \ 15 | --table_size_array "649,9364,14746,490,476707,11618,4142,1373,7275,13,169,407,1376,1460,583,10131227,2202608,305,24,12517,633,3,93145,5683,8351593,3194,27,14992,5461306,10,5652,2173,4,7046547,18,15,286181,105,142572" \ 16 | --store_type 'cached_host_mem' \ 17 | --cache_memory_budget_mb 2048 \ 18 | --dnn_hidden_units "1000, 1000, 1000, 1000, 1000" \ 19 | --crossing_layers 4 \ 20 | --embedding_vec_size 16 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /RecommenderSystems/deepfm/tools/launch_spark.sh: -------------------------------------------------------------------------------- 1 | export SPARK_LOCAL_DIRS=/tmp/tmp_spark 2 | spark-shell \ 3 | --master "local[*]" \ 4 | --conf spark.driver.maxResultSize=0 \ 5 | --driver-memory 360G 6 | -------------------------------------------------------------------------------- /RecommenderSystems/dlrm/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/RecommenderSystems/dlrm/__init__.py -------------------------------------------------------------------------------- /RecommenderSystems/dlrm/requirements.txt: -------------------------------------------------------------------------------- 1 | petastorm 2 | psutil 3 | -------------------------------------------------------------------------------- /RecommenderSystems/dlrm/tools/launch_spark.sh: -------------------------------------------------------------------------------- 1 | export SPARK_LOCAL_DIRS=/tmp/tmp_spark 2 | spark-shell \ 3 | --master "local[*]" \ 4 | --conf spark.driver.maxResultSize=0 \ 5 | --driver-memory 360G 6 | -------------------------------------------------------------------------------- /RecommenderSystems/dlrm/tools/split_day_23.sh: -------------------------------------------------------------------------------- 1 | # split day_23 to test.csv and val.csv 2 | src_dir=${1:-"/workspace/dataset/criteo1t/raw"} 3 | tmp_dir=${2:-"/workspace/tmp_spark"} 4 | 5 | mkdir -p $tmp_dir 6 | 7 | # total 178274637, test 89137319, val 89137318 8 | head -n 89137319 $src_dir/day_23 > $tmp_dir/test.csv 9 | tail -n +89137320 $src_dir/day_23 > $tmp_dir/val.csv 10 | -------------------------------------------------------------------------------- /RecommenderSystems/mmoe/train_mmoe.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | DEVICE_NUM_PER_NODE=1 3 | DATA_DIR=/path/to/mmoe_parquet 4 | PERSISTENT_PATH=/path/to/persistent 5 | MODEL_SAVE_DIR=/path/to/model/save/dir 6 | 7 | python3 -m oneflow.distributed.launch \ 8 | --nproc_per_node $DEVICE_NUM_PER_NODE \ 9 | --nnodes 1 \ 10 | --node_rank 0 \ 11 | --master_addr 127.0.0.1 \ 12 | mmoe_train_eval.py \ 13 | --data_dir $DATA_DIR \ 14 | --persistent_path $PERSISTENT_PATH \ 15 | --table_size_array "9, 52, 47, 17, 3, 24, 15, 5, 10, 2, 3, 6, 8, 6, 6, 51, 38, 8, 10, 9, 10, 3, 4, 5, 43, 43, 43, 5, 3" \ 16 | --store_type 'cached_host_mem' \ 17 | --cache_memory_budget_mb 1024 \ 18 | --batch_size 256 \ 19 | --train_batches 16000 \ 20 | --loss_print_interval 100 \ 21 | --learning_rate 0.001 \ 22 | --embedding_vec_size 4 \ 23 | --expert_dnn "256, 128" \ 24 | --num_train_samples 199523 \ 25 | --num_test_samples 99762 \ 26 | --model_save_dir $MODEL_SAVE_DIR 27 | -------------------------------------------------------------------------------- /RecommenderSystems/pnn/tools/launch_spark.sh: -------------------------------------------------------------------------------- 1 | export SPARK_LOCAL_DIRS=/tmp/tmp_spark 2 | spark-shell \ 3 | --master "local[*]" \ 4 | --conf spark.driver.maxResultSize=0 \ 5 | --driver-memory 360G -------------------------------------------------------------------------------- /RecommenderSystems/wide_and_deep/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/RecommenderSystems/wide_and_deep/__init__.py -------------------------------------------------------------------------------- /RecommenderSystems/wide_and_deep/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/RecommenderSystems/wide_and_deep/models/__init__.py -------------------------------------------------------------------------------- /RecommenderSystems/wide_and_deep/train_ddp.sh: -------------------------------------------------------------------------------- 1 | DEVICE_NUM_PER_NODE=1 2 | MASTER_ADDR=127.0.0.1 3 | NUM_NODES=1 4 | NODE_RANK=0 5 | DATA_DIR=/dataset/wdl_ofrecord/ofrecord 6 | EMBD_SIZE=2322444 7 | BATHSIZE=2048 8 | 9 | python3 -m oneflow.distributed.launch \ 10 | --nproc_per_node $DEVICE_NUM_PER_NODE \ 11 | --nnodes $NUM_NODES \ 12 | --node_rank $NODE_RANK \ 13 | --master_addr $MASTER_ADDR \ 14 | train.py \ 15 | --learning_rate 0.001 \ 16 | --batch_size $BATHSIZE \ 17 | --data_dir $DATA_DIR \ 18 | --loss_print_every_n_iter 100 \ 19 | --eval_interval 0 \ 20 | --deep_dropout_rate 0.5 \ 21 | --max_iter 310 \ 22 | --hidden_units_num 7 \ 23 | --hidden_size 1024 \ 24 | --wide_vocab_size $EMBD_SIZE \ 25 | --deep_vocab_size $EMBD_SIZE \ 26 | --data_part_num 256 \ 27 | --data_part_name_suffix_length 5 \ 28 | --ddp \ 29 | --test_name 'train_ddp_'$DEVICE_NUM_PER_NODE'gpu' 30 | -------------------------------------------------------------------------------- /RecommenderSystems/wide_and_deep/train_global_eager.sh: -------------------------------------------------------------------------------- 1 | DEVICE_NUM_PER_NODE=1 2 | MASTER_ADDR=127.0.0.1 3 | NUM_NODES=1 4 | NODE_RANK=0 5 | DATA_DIR=/dataset/wdl_ofrecord/ofrecord 6 | EMBD_SIZE=2322444 7 | BATHSIZE=2048 8 | 9 | python3 -m oneflow.distributed.launch \ 10 | --nproc_per_node $DEVICE_NUM_PER_NODE \ 11 | --nnodes $NUM_NODES \ 12 | --node_rank $NODE_RANK \ 13 | --master_addr $MASTER_ADDR \ 14 | train.py \ 15 | --learning_rate 0.001 \ 16 | --batch_size $BATHSIZE \ 17 | --data_dir $DATA_DIR \ 18 | --loss_print_every_n_iter 100 \ 19 | --eval_interval 0 \ 20 | --deep_dropout_rate 0.5 \ 21 | --max_iter 310 \ 22 | --hidden_units_num 7 \ 23 | --hidden_size 1024 \ 24 | --wide_vocab_size $EMBD_SIZE \ 25 | --deep_vocab_size $EMBD_SIZE \ 26 | --data_part_num 256 \ 27 | --data_part_name_suffix_length 5 \ 28 | --execution_mode 'eager' \ 29 | --test_name 'train_global_eager_'$DEVICE_NUM_PER_NODE'gpu' 30 | -------------------------------------------------------------------------------- /RecommenderSystems/wide_and_deep/train_global_graph.sh: -------------------------------------------------------------------------------- 1 | DEVICE_NUM_PER_NODE=1 2 | MASTER_ADDR=127.0.0.1 3 | NUM_NODES=1 4 | NODE_RANK=0 5 | DATA_DIR=/dataset/wdl_ofrecord/ofrecord 6 | EMBD_SIZE=2322444 7 | BATHSIZE=2048 8 | 9 | python3 -m oneflow.distributed.launch \ 10 | --nproc_per_node $DEVICE_NUM_PER_NODE \ 11 | --nnodes $NUM_NODES \ 12 | --node_rank $NODE_RANK \ 13 | --master_addr $MASTER_ADDR \ 14 | train.py \ 15 | --learning_rate 0.001 \ 16 | --batch_size $BATHSIZE \ 17 | --data_dir $DATA_DIR \ 18 | --loss_print_every_n_iter 10 \ 19 | --eval_interval 0 \ 20 | --deep_dropout_rate 0.5 \ 21 | --max_iter 31 \ 22 | --hidden_units_num 2 \ 23 | --hidden_size 1024 \ 24 | --wide_vocab_size $EMBD_SIZE \ 25 | --deep_vocab_size $EMBD_SIZE \ 26 | --data_part_num 256 \ 27 | --data_part_name_suffix_length 5 \ 28 | --execution_mode 'graph' \ 29 | --test_name 'train_global_graph_'$DEVICE_NUM_PER_NODE'gpu' 30 | -------------------------------------------------------------------------------- /RecommenderSystems/xdeepfm/tools/launch_spark.sh: -------------------------------------------------------------------------------- 1 | export SPARK_LOCAL_DIRS=/tmp/tmp_spark 2 | spark-shell \ 3 | --master "local[*]" \ 4 | --conf spark.driver.maxResultSize=0 \ 5 | --driver-memory 360G 6 | -------------------------------------------------------------------------------- /Vision/BJTU_summer_tournament/requirements.txt: -------------------------------------------------------------------------------- 1 | flowvision==0.2.0 2 | numpy==1.21.2 3 | oneflow==0.8.0+cu112 4 | opencv_python_headless==4.5.3.56 5 | -------------------------------------------------------------------------------- /Vision/LSTM/EnResLSTM/run.sh: -------------------------------------------------------------------------------- 1 | python train.py -------------------------------------------------------------------------------- /Vision/classification/image/DLA/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="pretrain_model/epoch_1396_val_acc_0.921875" 4 | IMAGE_PATH="data/bus.jpg" 5 | # IMAGE_PATH="data/tiger.jpg" 6 | # IMAGE_PATH="data/ILSVRC2012_val_00020287.JPEG" 7 | 8 | if [ ! -d "data" ]; then 9 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/models/DLA/data.zip 10 | unzip data.zip 11 | fi 12 | 13 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 14 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/DLA/pretrain_model.zip 15 | unzip pretrain_model.zip 16 | fi 17 | 18 | python3 infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 19 | -------------------------------------------------------------------------------- /Vision/classification/image/DLA/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy==1.19.5 2 | Pillow==8.3.1 3 | -------------------------------------------------------------------------------- /Vision/classification/image/DLA/train_oneflow.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="./DLAdataset_ofrecord/ofrecord/trainData" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/models/DLA/DLAdataset_ofrecord.zip 6 | unzip DLAdataset_ofrecord.zip 7 | fi 8 | 9 | CHECKPOINT_PATH="checkpoints" 10 | if [ ! -d "$CHECKPOINT_PATH" ]; then 11 | mkdir $CHECKPOINT_PATH 12 | fi 13 | 14 | LEARNING_RATE=0.001 15 | MOM=0.9 16 | EPOCH=1200 17 | TRAIN_BATCH_SIZE=32 18 | VAL_BATCH_SIZE=32 19 | 20 | # LOAD PREVIOUS CHECKPOINT 21 | # LOAD_CHECKPOINT=$pretrain_model/ 22 | 23 | python3 train_oneflow.py \ 24 | --save_checkpoint_path $CHECKPOINT_PATH \ 25 | --ofrecord_path $OFRECORD_PATH \ 26 | --learning_rate $LEARNING_RATE \ 27 | --mom $MOM \ 28 | --epochs $EPOCH \ 29 | --train_batch_size $TRAIN_BATCH_SIZE \ 30 | --val_batch_size $VAL_BATCH_SIZE \ 31 | # --load_checkpoint $LOAD_CHECKPOINT 32 | -------------------------------------------------------------------------------- /Vision/classification/image/DLA/utils/clsidx_to_labels.py: -------------------------------------------------------------------------------- 1 | clsidx_2_labels = { 2 | 0: "bus", 3 | 1: "family sedan", 4 | 2: "fire engine", 5 | 3: "heavy truck", 6 | 4: "jeep", 7 | 5: "minibus", 8 | 6: "racing car", 9 | 7: "SUV", 10 | 8: "taxi", 11 | 9: "truck", 12 | } 13 | -------------------------------------------------------------------------------- /Vision/classification/image/DLA/utils/numpy_data_utils.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import numpy as np 3 | import os 4 | import random 5 | 6 | 7 | def load_image(image_path="data/jeep.jpg"): 8 | rgb_mean = [123.68, 116.779, 103.939] 9 | rgb_std = [58.393, 57.12, 57.375] 10 | im = Image.open(image_path) 11 | im = im.resize((224, 224)) 12 | im = im.convert("RGB") 13 | im = np.array(im).astype("float32") 14 | im = (im - rgb_mean) / rgb_std 15 | im = np.transpose(im, (2, 0, 1)) 16 | im = np.expand_dims(im, axis=0) 17 | return np.ascontiguousarray(im, "float32") 18 | -------------------------------------------------------------------------------- /Vision/classification/image/ViT/eager/infer.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | IMAGE_PATH="data/fish.jpg" 5 | # Note that We only provide pretrained model weight under image_size=384 6 | # Model Arch: ['vit_b_16_384', 'vit_b_32_384', 'vit_l_16_384', 'vit_l_32_384'] 7 | PRETRAIN_MODEL_PATH="./vit_b_16_384" 8 | MODEL_ARCH="vit_b_16_384" 9 | IMAGE_SIZE=384 10 | 11 | 12 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 13 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/ViT-OneFlow/$MODEL_ARCH.zip 14 | unzip $MODEL_ARCH.zip 15 | fi 16 | 17 | 18 | if [ ! -d "data" ]; then 19 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 20 | tar zxf data.tar.gz 21 | fi 22 | 23 | 24 | python3 eager/infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH --model_arch $MODEL_ARCH --image_size $IMAGE_SIZE 25 | -------------------------------------------------------------------------------- /Vision/classification/image/ViT/graph/infer.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | IMAGE_PATH="data/fish.jpg" 5 | # Note that We only provide pretrained model weight under image_size=384 6 | # Model Arch: ['vit_b_16_384', 'vit_b_32_384', 'vit_l_16_384', 'vit_l_32_384'] 7 | PRETRAIN_MODEL_PATH="./vit_b_16_384" 8 | MODEL_ARCH="vit_b_16_384" 9 | IMAGE_SIZE=384 10 | 11 | 12 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 13 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/ViT-OneFlow/$MODEL_ARCH.zip 14 | unzip $MODEL_ARCH.zip 15 | fi 16 | 17 | 18 | if [ ! -d "data" ]; then 19 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 20 | tar zxf data.tar.gz 21 | fi 22 | 23 | 24 | python3 graph/infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH --model_arch $MODEL_ARCH --image_size $IMAGE_SIZE 25 | -------------------------------------------------------------------------------- /Vision/classification/image/ViT/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/ViT/model/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/ViT/model/build_model.py: -------------------------------------------------------------------------------- 1 | from model.vit import ( 2 | ViT_B_16_224, 3 | ViT_B_16_384, 4 | ViT_B_32_224, 5 | ViT_B_32_384, 6 | ViT_L_16_384, 7 | ViT_L_32_384, 8 | ) 9 | 10 | 11 | def build_model(args): 12 | if args.model_arch == "vit_b_16_224": 13 | return ViT_B_16_224() 14 | elif args.model_arch == "vit_b_16_384": 15 | return ViT_B_16_384() 16 | elif args.model_arch == "vit_b_32_224": 17 | return ViT_B_32_224() 18 | elif args.model_arch == "vit_b_32_384": 19 | return ViT_B_32_384() 20 | elif args.model_arch == "vit_l_16_384": 21 | return ViT_L_16_384() 22 | elif args.model_arch == "vit_l_32_384": 23 | return ViT_L_32_384() 24 | -------------------------------------------------------------------------------- /Vision/classification/image/ViT/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | Pillow 4 | -------------------------------------------------------------------------------- /Vision/classification/image/ViT/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/ViT/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/alexnet/check/check.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="ofrecord" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 6 | tar zxf imagenette_ofrecord.tar.gz 7 | fi 8 | 9 | CHECKPOINT_PATH="checkpoints" 10 | if [ ! -d "$CHECKPOINT_PATH" ]; then 11 | mkdir $CHECKPOINT_PATH 12 | fi 13 | 14 | LEARNING_RATE=0.001 15 | MOM=0.9 16 | EPOCH=20 17 | TRAIN_BATCH_SIZE=16 18 | VAL_BATCH_SIZE=16 19 | 20 | python3 check/check.py \ 21 | --save_checkpoint_path $CHECKPOINT_PATH \ 22 | --ofrecord_path $OFRECORD_PATH \ 23 | --learning_rate $LEARNING_RATE \ 24 | --mom $MOM \ 25 | --epochs $EPOCH \ 26 | --train_batch_size $TRAIN_BATCH_SIZE \ 27 | --val_batch_size $VAL_BATCH_SIZE \ 28 | 29 | 30 | -------------------------------------------------------------------------------- /Vision/classification/image/alexnet/check/draw.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | TXT_ROOT="results/default/" 4 | SAVE_ROOT="results/picture/" 5 | 6 | python3 check/draw.py \ 7 | --txt_root $TXT_ROOT \ 8 | --save_root $SAVE_ROOT \ -------------------------------------------------------------------------------- /Vision/classification/image/alexnet/eager/infer.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | PRETRAIN_MODEL_PATH="./alexnet_oneflow_model" 5 | IMAGE_PATH="data/fish.jpg" 6 | 7 | if [ ! -d "data" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 9 | tar zxf data.tar.gz 10 | fi 11 | 12 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 13 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/alexnet/alexnet_oneflow_model.tar.gz 14 | tar -xzvf alexnet_oneflow_model.tar.gz 15 | fi 16 | 17 | python3 eager/infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 18 | -------------------------------------------------------------------------------- /Vision/classification/image/alexnet/eager/train.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | OFRECORD_PATH="ofrecord" 5 | if [ ! -d "$OFRECORD_PATH" ]; then 6 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 7 | tar zxf imagenette_ofrecord.tar.gz 8 | fi 9 | 10 | CHECKPOINT_PATH="checkpoints" 11 | if [ ! -d "$CHECKPOINT_PATH" ]; then 12 | mkdir $CHECKPOINT_PATH 13 | fi 14 | 15 | LEARNING_RATE=0.001 16 | MOM=0.9 17 | EPOCH=20 18 | TRAIN_BATCH_SIZE=16 19 | VAL_BATCH_SIZE=16 20 | 21 | 22 | python3 eager/train.py \ 23 | --save_checkpoint_path $CHECKPOINT_PATH \ 24 | --ofrecord_path $OFRECORD_PATH \ 25 | --learning_rate $LEARNING_RATE \ 26 | --mom $MOM \ 27 | --epochs $EPOCH \ 28 | --train_batch_size $TRAIN_BATCH_SIZE \ 29 | --val_batch_size $VAL_BATCH_SIZE \ 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Vision/classification/image/alexnet/graph/infer.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | PRETRAIN_MODEL_PATH="./alexnet_oneflow_model" 5 | IMAGE_PATH="data/fish.jpg" 6 | 7 | if [ ! -d "data" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 9 | tar zxf data.tar.gz 10 | fi 11 | 12 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 13 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/alexnet/alexnet_oneflow_model.tar.gz 14 | tar -xzvf alexnet_oneflow_model.tar.gz 15 | fi 16 | 17 | python3 graph/infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 18 | -------------------------------------------------------------------------------- /Vision/classification/image/alexnet/graph/train.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | OFRECORD_PATH="ofrecord" 5 | if [ ! -d "$OFRECORD_PATH" ]; then 6 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 7 | tar zxf imagenette_ofrecord.tar.gz 8 | fi 9 | 10 | CHECKPOINT_PATH="checkpoints" 11 | if [ ! -d "$CHECKPOINT_PATH" ]; then 12 | mkdir $CHECKPOINT_PATH 13 | fi 14 | 15 | LEARNING_RATE=0.001 16 | MOM=0.9 17 | EPOCH=20 18 | TRAIN_BATCH_SIZE=16 19 | VAL_BATCH_SIZE=16 20 | 21 | 22 | python3 graph/train.py \ 23 | --save_checkpoint_path $CHECKPOINT_PATH \ 24 | --ofrecord_path $OFRECORD_PATH \ 25 | --learning_rate $LEARNING_RATE \ 26 | --mom $MOM \ 27 | --epochs $EPOCH \ 28 | --train_batch_size $TRAIN_BATCH_SIZE \ 29 | --val_batch_size $VAL_BATCH_SIZE \ 30 | 31 | 32 | -------------------------------------------------------------------------------- /Vision/classification/image/alexnet/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/alexnet/model/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/alexnet/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | Pillow 4 | tqdm -------------------------------------------------------------------------------- /Vision/classification/image/alexnet/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/alexnet/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/alexnet/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /Vision/classification/image/densenet/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="./densenet_121_oneflow_model" 4 | IMAGE_PATH="data/fish.jpg" 5 | # IMAGE_PATH="data/tiger.jpg" 6 | # IMAGE_PATH="data/ILSVRC2012_val_00020287.JPEG" 7 | 8 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 9 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/densenet/densenet_121_oneflow_model.zip 10 | unzip densenet_121_oneflow_model.zip 11 | fi 12 | 13 | if [ ! -d "data" ]; then 14 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 15 | tar zxf data.tar.gz 16 | fi 17 | 18 | python3 infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 19 | -------------------------------------------------------------------------------- /Vision/classification/image/densenet/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/densenet/models/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/densenet/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | Pillow 4 | -------------------------------------------------------------------------------- /Vision/classification/image/densenet/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="ofrecord" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 6 | tar zxf imagenette_ofrecord.tar.gz 7 | fi 8 | 9 | CHECKPOINT_PATH="checkpoints" 10 | if [ ! -d "$CHECKPOINT_PATH" ]; then 11 | mkdir $CHECKPOINT_PATH 12 | fi 13 | 14 | LEARNING_RATE=0.001 15 | MOM=0.9 16 | EPOCH=20 17 | TRAIN_BATCH_SIZE=16 18 | VAL_BATCH_SIZE=16 19 | 20 | # LOAD PREVIOUS CHECKPOINT 21 | # LOAD_CHECKPOINT="/PATH/TO/CHECKPOINT" 22 | 23 | python3 train.py \ 24 | --save_checkpoint_path $CHECKPOINT_PATH \ 25 | --ofrecord_path $OFRECORD_PATH \ 26 | --learning_rate $LEARNING_RATE \ 27 | --mom $MOM \ 28 | --epochs $EPOCH \ 29 | --train_batch_size $TRAIN_BATCH_SIZE \ 30 | --val_batch_size $VAL_BATCH_SIZE \ 31 | # --load_checkpoint $LOAD_CHECKPOINT 32 | 33 | 34 | -------------------------------------------------------------------------------- /Vision/classification/image/densenet/utils/Figure_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/densenet/utils/Figure_1.png -------------------------------------------------------------------------------- /Vision/classification/image/densenet/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/densenet/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/densenet/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /Vision/classification/image/ghostnet/README.md: -------------------------------------------------------------------------------- 1 | # GhostNet 2 | 3 | This repo is based on: https://github.com/huawei-noah/CV-Backbones/tree/master/ghostnet_pytorch/ghostnet.py 4 | 5 | 6 | #### Download Ofrecord 7 | 8 | ```bash 9 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 10 | tar zxf imagenette_ofrecord.tar.gz 11 | ``` 12 | 13 | ## Run Oneflow Training script 14 | 15 | ```bash 16 | bash train_oneflow.sh 17 | ``` 18 | 19 | 20 | ## Inference on Single Image 21 | 22 | ```bash 23 | bash infer.sh 24 | ``` 25 | 26 | 27 | ## Compare with pytorch_ghostnet 28 | 29 | ![Compare of loss](https://github.com/Oneflow-Inc/models/ghostnet/utils/ghostnet_compare.png) 30 | 31 | -------------------------------------------------------------------------------- /Vision/classification/image/ghostnet/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="ghostnet_imagenet_pretrain_model/" 4 | MODEL="ghostnet" #choose from ghostnet 5 | 6 | # IMAGE_PATH="data/fish.jpg" 7 | IMAGE_PATH="data/tiger.jpg" 8 | # IMAGE_PATH="data/ILSVRC2012_val_00020287.JPEG" 9 | 10 | if [ ! -d "data" ]; then 11 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 12 | tar zxf data.tar.gz 13 | fi 14 | 15 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 16 | mkdir ${PRETRAIN_MODEL_PATH} 17 | fi 18 | 19 | if [ ! -d "${PRETRAIN_MODEL_PATH}/checkpoints/epoch_484_val_acc_0.908418" ]; then 20 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/ghostnet/ghostnet_oneflow_model.tar.gz 21 | tar zxf ghostnet_oneflow_model.tar.gz --directory ${PRETRAIN_MODEL_PATH} 22 | fi 23 | 24 | python3 infer.py --model_path ${PRETRAIN_MODEL_PATH}/checkpoints/epoch_484_val_acc_0.908418 --image_path $IMAGE_PATH --model $MODEL 25 | -------------------------------------------------------------------------------- /Vision/classification/image/ghostnet/train_oneflow.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="ofrecord" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 6 | tar zxf imagenette_ofrecord.tar.gz 7 | fi 8 | 9 | CHECKPOINT_PATH="checkpoints" 10 | if [ ! -d "$CHECKPOINT_PATH" ]; then 11 | mkdir $CHECKPOINT_PATH 12 | fi 13 | 14 | LEARNING_RATE=0.001 15 | MOM=0.9 16 | EPOCH=1000 17 | TRAIN_BATCH_SIZE=16 18 | VAL_BATCH_SIZE=16 19 | MODEL=ghostnet 20 | 21 | # LOAD_CHECKPOINT="$CHECKPOINT_PATH/your_pretrain_model" 22 | # LOAD PREVIOUS CHECKPOINT 23 | 24 | python3 train_oneflow.py \ 25 | --save_checkpoint_path $CHECKPOINT_PATH \ 26 | --ofrecord_path $OFRECORD_PATH \ 27 | --learning_rate $LEARNING_RATE \ 28 | --mom $MOM \ 29 | --epochs $EPOCH \ 30 | --train_batch_size $TRAIN_BATCH_SIZE \ 31 | --val_batch_size $VAL_BATCH_SIZE \ 32 | --model $MODEL \ 33 | #--load_checkpoint $LOAD_CHECKPOINT 34 | 35 | 36 | -------------------------------------------------------------------------------- /Vision/classification/image/ghostnet/utils/ghostnet_compare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/ghostnet/utils/ghostnet_compare.png -------------------------------------------------------------------------------- /Vision/classification/image/inception_v3/eager/infer.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | PRETRAIN_MODEL_PATH="./inceptionv3_oneflow_model" 5 | IMAGE_PATH="data/fish.jpg" 6 | # IMAGE_PATH="data/tiger.jpg" 7 | # IMAGE_PATH="data/ILSVRC2012_val_00020287.JPEG" 8 | 9 | if [ ! -d "data" ]; then 10 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 11 | tar zxf data.tar.gz 12 | fi 13 | 14 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 15 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/inceptionv3/inceptionv3_oneflow_model.tar.gz 16 | tar -xzvf inceptionv3_oneflow_model.tar.gz 17 | fi 18 | 19 | python3 eager/infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 20 | -------------------------------------------------------------------------------- /Vision/classification/image/inception_v3/eager/train.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | OFRECORD_PATH="ofrecord" 5 | if [ ! -d "$OFRECORD_PATH" ]; then 6 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 7 | tar zxf imagenette_ofrecord.tar.gz 8 | fi 9 | 10 | CHECKPOINT_PATH="checkpoints" 11 | if [ ! -d "$CHECKPOINT_PATH" ]; then 12 | mkdir $CHECKPOINT_PATH 13 | fi 14 | 15 | LEARNING_RATE=0.001 16 | MOM=0.9 17 | EPOCH=20 18 | TRAIN_BATCH_SIZE=16 19 | VAL_BATCH_SIZE=16 20 | 21 | # LOAD PREVIOUS CHECKPOINT 22 | # LOAD_CHECKPOINT=$CHECKPOINT_PATH/epoch_2_val_acc_0.111168 23 | 24 | python3 eager/train.py \ 25 | --save_checkpoint_path $CHECKPOINT_PATH \ 26 | --ofrecord_path $OFRECORD_PATH \ 27 | --learning_rate $LEARNING_RATE \ 28 | --mom $MOM \ 29 | --epochs $EPOCH \ 30 | --train_batch_size $TRAIN_BATCH_SIZE \ 31 | --val_batch_size $VAL_BATCH_SIZE \ 32 | # --load_checkpoint $LOAD_CHECKPOINT 33 | 34 | 35 | -------------------------------------------------------------------------------- /Vision/classification/image/inception_v3/graph/infer.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | PRETRAIN_MODEL_PATH="./inceptionv3_oneflow_model" 5 | IMAGE_PATH="data/fish.jpg" 6 | 7 | if [ ! -d "data" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 9 | tar zxf data.tar.gz 10 | fi 11 | 12 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 13 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/inceptionv3/inceptionv3_oneflow_model.tar.gz 14 | tar -xzvf inceptionv3_oneflow_model.tar.gz 15 | fi 16 | 17 | python3 graph/infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 18 | -------------------------------------------------------------------------------- /Vision/classification/image/inception_v3/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/inception_v3/models/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/inception_v3/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | pillow 4 | scipy 5 | -------------------------------------------------------------------------------- /Vision/classification/image/inception_v3/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/inception_v3/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/inception_v3/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /Vision/classification/image/mnasnet/eager/infer.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | PRETRAIN_MODEL_PATH="./weight/mnasnet0_5" 5 | IMAGE_PATH="data/fish.jpg" 6 | 7 | if [ ! -d "data" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 9 | tar zxf data.tar.gz 10 | fi 11 | 12 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 13 | mkdir weight 14 | cd weight 15 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/MNASNet/mnasnet0_5.zip 16 | unzip mnasnet0_5.zip 17 | cd .. 18 | fi 19 | 20 | python3 eager/infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH -------------------------------------------------------------------------------- /Vision/classification/image/mnasnet/eager/train.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | OFRECORD_PATH="ofrecord" 5 | if [ ! -d "$OFRECORD_PATH" ]; then 6 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 7 | tar zxf imagenette_ofrecord.tar.gz 8 | fi 9 | 10 | CHECKPOINT_PATH="checkpoints" 11 | if [ ! -d "$CHECKPOINT_PATH" ]; then 12 | mkdir $CHECKPOINT_PATH 13 | fi 14 | 15 | MODEL='mnasnet0_5' 16 | DATASET='imagenette' 17 | LEARNING_RATE=0.001 18 | MOM=0.9 19 | EPOCH=20 20 | TRAIN_BATCH_SIZE=16 21 | VAL_BATCH_SIZE=16 22 | 23 | 24 | python3 eager/train.py \ 25 | --model $MODEL \ 26 | --dataset $DATASET \ 27 | --save_checkpoint_path $CHECKPOINT_PATH \ 28 | --ofrecord_path $OFRECORD_PATH \ 29 | --learning_rate $LEARNING_RATE \ 30 | --mom $MOM \ 31 | --epochs $EPOCH \ 32 | --train_batch_size $TRAIN_BATCH_SIZE \ 33 | --val_batch_size $VAL_BATCH_SIZE \ 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Vision/classification/image/mnasnet/graph/infer.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | PRETRAIN_MODEL_PATH="./weight/mnasnet0_5" 5 | IMAGE_PATH="data/fish.jpg" 6 | 7 | if [ ! -d "data" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 9 | tar zxf data.tar.gz 10 | fi 11 | 12 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 13 | mkdir weight 14 | cd weight 15 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/MNASNet/mnasnet0_5.zip 16 | unzip mnasnet0_5.zip 17 | cd .. 18 | fi 19 | 20 | python3 graph/infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH -------------------------------------------------------------------------------- /Vision/classification/image/mnasnet/graph/train.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | OFRECORD_PATH="ofrecord" 5 | if [ ! -d "$OFRECORD_PATH" ]; then 6 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 7 | tar zxf imagenette_ofrecord.tar.gz 8 | fi 9 | 10 | CHECKPOINT_PATH="checkpoints" 11 | if [ ! -d "$CHECKPOINT_PATH" ]; then 12 | mkdir $CHECKPOINT_PATH 13 | fi 14 | 15 | MODEL='mnasnet0_5' 16 | DATASET='imagenette' 17 | LEARNING_RATE=0.001 18 | MOM=0.9 19 | EPOCH=20 20 | TRAIN_BATCH_SIZE=16 21 | VAL_BATCH_SIZE=16 22 | 23 | 24 | python3 graph/train.py \ 25 | --model $MODEL \ 26 | --dataset $DATASET \ 27 | --save_checkpoint_path $CHECKPOINT_PATH \ 28 | --ofrecord_path $OFRECORD_PATH \ 29 | --learning_rate $LEARNING_RATE \ 30 | --mom $MOM \ 31 | --epochs $EPOCH \ 32 | --train_batch_size $TRAIN_BATCH_SIZE \ 33 | --val_batch_size $VAL_BATCH_SIZE \ 34 | 35 | 36 | -------------------------------------------------------------------------------- /Vision/classification/image/mnasnet/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/mnasnet/model/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/mnasnet/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/mnasnet/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/mnasnet/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv2/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="./mobilenetv2_oneflow_model" 4 | IMAGE_PATH="data/fish.jpg" 5 | 6 | if [ ! -d "data" ]; then 7 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 8 | tar zxf data.tar.gz 9 | fi 10 | 11 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 12 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/mobilenetv2/mobilenetv2_oneflow_model.zip 13 | unzip mobilenetv2_oneflow_model.zip 14 | fi 15 | 16 | python3 infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 17 | -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv2/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/mobilenetv2/models/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv2/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | Pillow 4 | -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv2/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="ofrecord" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 6 | tar zxf imagenette_ofrecord.tar.gz 7 | fi 8 | 9 | CHECKPOINT_PATH="checkpoints" 10 | if [ ! -d "$CHECKPOINT_PATH" ]; then 11 | mkdir $CHECKPOINT_PATH 12 | fi 13 | 14 | LEARNING_RATE=0.001 15 | MOM=0.9 16 | EPOCH=20 17 | TRAIN_BATCH_SIZE=16 18 | VAL_BATCH_SIZE=16 19 | 20 | # LOAD PREVIOUS CHECKPOINT 21 | # LOAD_CHECKPOINT="PATH/TO/CHECKPOINT" 22 | 23 | python3 train.py \ 24 | --save_checkpoint_path $CHECKPOINT_PATH \ 25 | --ofrecord_path $OFRECORD_PATH \ 26 | --learning_rate $LEARNING_RATE \ 27 | --mom $MOM \ 28 | --epochs $EPOCH \ 29 | --train_batch_size $TRAIN_BATCH_SIZE \ 30 | --val_batch_size $VAL_BATCH_SIZE \ 31 | # --load_checkpoint $LOAD_CHECKPOINT 32 | 33 | 34 | -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv2/utils/Figure_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/mobilenetv2/utils/Figure_1.png -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv2/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/mobilenetv2/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv2/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv3/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="./mobilenetv3_oneflow_model" 4 | IMAGE_PATH="data/fish.jpg" 5 | # IMAGE_PATH="data/tiger.jpg" 6 | # IMAGE_PATH="data/ILSVRC2012_val_00020287.JPEG" 7 | 8 | if [ ! -d "data" ]; then 9 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 10 | tar zxf data.tar.gz 11 | fi 12 | 13 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 14 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/mobilenetv3/mobilenetv3_oneflow_model.tar.gz 15 | tar -xzvf mobilenetv3_oneflow_model.tar.gz 16 | fi 17 | 18 | python3 infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 19 | -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv3/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/mobilenetv3/models/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv3/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | Pillow 4 | -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv3/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="ofrecord" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 6 | tar zxf imagenette_ofrecord.tar.gz 7 | fi 8 | 9 | CHECKPOINT_PATH="checkpoints" 10 | if [ ! -d "$CHECKPOINT_PATH" ]; then 11 | mkdir $CHECKPOINT_PATH 12 | fi 13 | 14 | LEARNING_RATE=0.001 15 | MOM=0.9 16 | EPOCH=20 17 | TRAIN_BATCH_SIZE=16 18 | VAL_BATCH_SIZE=16 19 | 20 | # LOAD PREVIOUS CHECKPOINT 21 | # LOAD_CHECKPOINT=$CHECKPOINT_PATH/epoch_2_val_acc_0.111168 22 | 23 | python3 train.py \ 24 | --save_checkpoint_path $CHECKPOINT_PATH \ 25 | --ofrecord_path $OFRECORD_PATH \ 26 | --learning_rate $LEARNING_RATE \ 27 | --mom $MOM \ 28 | --epochs $EPOCH \ 29 | --train_batch_size $TRAIN_BATCH_SIZE \ 30 | --val_batch_size $VAL_BATCH_SIZE \ 31 | # --load_checkpoint $LOAD_CHECKPOINT 32 | 33 | 34 | -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv3/utils/Figure_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/mobilenetv3/utils/Figure_1.png -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv3/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/mobilenetv3/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/mobilenetv3/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /Vision/classification/image/poseNet/README.md: -------------------------------------------------------------------------------- 1 | # Posenet 2 | 3 | Posenet is a backbone network, we use it to classify face pose. 4 | 5 | ## Train on face pose dataset Dataset 6 | The face pose dataset can be downloaded from [BaiduNetdis](https://pan.baidu.com/s/1KbrMUrUIS_cCzpDgdgjMRQ) code: o9tg . 7 | 8 | #### Download Ofrecord 9 | 10 | ```bash 11 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/models/pose/pose_dataset.zip 12 | unzip pose_dataset.zip 13 | ``` 14 | 15 | ### Run Oneflow Training script 16 | 17 | ``` 18 | pip3 install -r requirements.txt --user 19 | ``` 20 | 21 | ```bash 22 | bash train_oneflow.sh 23 | ``` 24 | ## Inference on Single Image 25 | 26 | ```bash 27 | bash infer.sh 28 | ``` 29 | 30 | ### Accuracy 31 | | | val(Top1) | 32 | | :-----: | :-----------------: | 33 | | Posenet | 0.906 | 34 | -------------------------------------------------------------------------------- /Vision/classification/image/poseNet/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="epoch_959_val_acc_0.906250" 4 | 5 | IMAGE_PATH="data/0-1.jpg" 6 | 7 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/pose/posenet_pretrain_model.tar.gz 9 | tar zxf posenet_pretrain_model.tar.gz 10 | fi 11 | 12 | if [ ! -d "IMAGE_PATH" ]; then 13 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/pose/data.tar.gz 14 | tar zxf data.tar.gz 15 | fi 16 | 17 | python3 infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 18 | -------------------------------------------------------------------------------- /Vision/classification/image/poseNet/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | oneflow 4 | Pillow 5 | -------------------------------------------------------------------------------- /Vision/classification/image/poseNet/train_oneflow.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | 4 | OFRECORD_PATH="pose_dataset" 5 | 6 | if [ ! -d "$OFRECORD_PATH" ]; then 7 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/models/pose/pose_dataset.zip 8 | unzip pose_dataset.zip 9 | fi 10 | 11 | CHECKPOINT_PATH="checkpoints" 12 | if [ ! -d "$CHECKPOINT_PATH" ]; then 13 | mkdir $CHECKPOINT_PATH 14 | fi 15 | 16 | LEARNING_RATE=0.001 17 | MOM=0.9 18 | EPOCH=1000 19 | TRAIN_BATCH_SIZE=32 20 | VAL_BATCH_SIZE=32 21 | 22 | # LOAD PREVIOUS CHECKPOINT 23 | # LOAD_CHECKPOINT=$CHECKPOINT_PATH/epoch_959_val_acc_0.906250 24 | 25 | python3 train_oneflow.py \ 26 | --save_checkpoint_path $CHECKPOINT_PATH \ 27 | --ofrecord_path $OFRECORD_PATH \ 28 | --learning_rate $LEARNING_RATE \ 29 | --mom $MOM \ 30 | --epochs $EPOCH \ 31 | --train_batch_size $TRAIN_BATCH_SIZE \ 32 | --val_batch_size $VAL_BATCH_SIZE \ 33 | # --load_checkpoint $LOAD_CHECKPOINT 34 | 35 | 36 | -------------------------------------------------------------------------------- /Vision/classification/image/poseNet/utils/clsidx_to_labels.py: -------------------------------------------------------------------------------- 1 | clsidx_2_labels = { 2 | 0: "frontal", 3 | 1: "profile45", 4 | 2: "profile75", 5 | 3: "upward", 6 | 4: "downward", 7 | } 8 | -------------------------------------------------------------------------------- /Vision/classification/image/repvgg/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="./repvggA0_oneflow_model" 4 | IMAGE_PATH="data/fish.jpg" 5 | # IMAGE_PATH="data/tiger.jpg" 6 | # IMAGE_PATH="data/ILSVRC2012_val_00020287.JPEG" 7 | 8 | if [ ! -d "data" ]; then 9 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 10 | tar zxf data.tar.gz 11 | fi 12 | 13 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 14 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/repvgg/repvggA0_oneflow_model.tar.gz 15 | tar -xzvf repvggA0_oneflow_model.tar.gz 16 | fi 17 | 18 | python3 infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 19 | -------------------------------------------------------------------------------- /Vision/classification/image/repvgg/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | Pillow 4 | -------------------------------------------------------------------------------- /Vision/classification/image/repvgg/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="ofrecord" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 6 | tar zxf imagenette_ofrecord.tar.gz 7 | fi 8 | 9 | CHECKPOINT_PATH="checkpoints" 10 | if [ ! -d "$CHECKPOINT_PATH" ]; then 11 | mkdir $CHECKPOINT_PATH 12 | fi 13 | 14 | LEARNING_RATE=0.001 15 | MOM=0.9 16 | EPOCH=20 17 | TRAIN_BATCH_SIZE=16 18 | VAL_BATCH_SIZE=16 19 | 20 | # LOAD PREVIOUS CHECKPOINT 21 | # LOAD_CHECKPOINT=$CHECKPOINT_PATH/epoch_2_val_acc_0.111168 22 | 23 | python3 train.py \ 24 | --save_checkpoint_path $CHECKPOINT_PATH \ 25 | --ofrecord_path $OFRECORD_PATH \ 26 | --learning_rate $LEARNING_RATE \ 27 | --mom $MOM \ 28 | --epochs $EPOCH \ 29 | --train_batch_size $TRAIN_BATCH_SIZE \ 30 | --val_batch_size $VAL_BATCH_SIZE \ 31 | # --load_checkpoint $LOAD_CHECKPOINT 32 | -------------------------------------------------------------------------------- /Vision/classification/image/repvgg/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/repvgg/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/repvgg/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /Vision/classification/image/resnet50/check/check.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="ofrecord" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 6 | tar zxf imagenette_ofrecord.tar.gz 7 | fi 8 | 9 | CHECKPOINT_PATH="checkpoints" 10 | if [ ! -d "$CHECKPOINT_PATH" ]; then 11 | mkdir $CHECKPOINT_PATH 12 | fi 13 | 14 | LEARNING_RATE=0.001 15 | MOM=0.9 16 | EPOCH=20 17 | TRAIN_BATCH_SIZE=16 18 | VAL_BATCH_SIZE=16 19 | 20 | python3 check/check.py \ 21 | --save_checkpoint_path $CHECKPOINT_PATH \ 22 | --ofrecord_path $OFRECORD_PATH \ 23 | --learning_rate $LEARNING_RATE \ 24 | --mom $MOM \ 25 | --epochs $EPOCH \ 26 | --train_batch_size $TRAIN_BATCH_SIZE \ 27 | --val_batch_size $VAL_BATCH_SIZE \ -------------------------------------------------------------------------------- /Vision/classification/image/resnet50/check/draw.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | TXT_ROOT="results/default/" 4 | SAVE_ROOT="results/picture/" 5 | 6 | python3 check/draw.py \ 7 | --txt_root $TXT_ROOT \ 8 | --save_root $SAVE_ROOT \ -------------------------------------------------------------------------------- /Vision/classification/image/resnet50/examples/infer.sh: -------------------------------------------------------------------------------- 1 | # set -aux 2 | 3 | PRETRAIN_MODEL_PATH="resnet50_imagenet_pretrain_model" 4 | IMAGE_PATH="data/fish.jpg" 5 | 6 | if [ ! -d "data" ]; then 7 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 8 | tar zxf data.tar.gz 9 | fi 10 | 11 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 12 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/resnet50_imagenet_pretrain_model.tar.gz 13 | tar zxf resnet50_imagenet_pretrain_model.tar.gz 14 | fi 15 | 16 | # SRC_DIR=/path/to/models/resnet50 17 | SRC_DIR=$(realpath $(dirname $0)/..) 18 | 19 | python3 $SRC_DIR/infer.py \ 20 | --model $PRETRAIN_MODEL_PATH \ 21 | --image $IMAGE_PATH \ 22 | -------------------------------------------------------------------------------- /Vision/classification/image/resnet50/examples/infer_graph.sh: -------------------------------------------------------------------------------- 1 | # set -aux 2 | 3 | PRETRAIN_MODEL_PATH="resnet50_imagenet_pretrain_model" 4 | IMAGE_PATH="data/fish.jpg" 5 | 6 | if [ ! -d "data" ]; then 7 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 8 | tar zxf data.tar.gz 9 | fi 10 | 11 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 12 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/resnet50_imagenet_pretrain_model.tar.gz 13 | tar zxf resnet50_imagenet_pretrain_model.tar.gz 14 | fi 15 | 16 | # SRC_DIR=/path/to/models/resnet50 17 | SRC_DIR=$(realpath $(dirname $0)/..) 18 | 19 | python3 $SRC_DIR/infer.py \ 20 | --model $PRETRAIN_MODEL_PATH \ 21 | --image $IMAGE_PATH \ 22 | --graph \ 23 | -------------------------------------------------------------------------------- /Vision/classification/image/resnet50/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/resnet50/models/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/resnet50/models/accuracy.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import oneflow as flow 3 | 4 | 5 | class Accuracy(flow.nn.Module): 6 | def __init__(self): 7 | super().__init__() 8 | 9 | def forward(self, preds, labels): 10 | top1_num = flow.zeros(1, dtype=flow.float32) 11 | num_samples = 0 12 | for pred, label in zip(preds, labels): 13 | clsidxs = pred.argmax(dim=-1) 14 | clsidxs = clsidxs.to(flow.int32) 15 | match = (clsidxs == label).sum() 16 | top1_num += match.to(device=top1_num.device, dtype=top1_num.dtype) 17 | num_samples += np.prod(label.shape).item() 18 | 19 | top1_acc = top1_num / num_samples 20 | return top1_acc 21 | -------------------------------------------------------------------------------- /Vision/classification/image/resnet50/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | torch 4 | Pillow 5 | -------------------------------------------------------------------------------- /Vision/classification/image/resnet50/utils/Figure_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/resnet50/utils/Figure_1.png -------------------------------------------------------------------------------- /Vision/classification/image/resnet50/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/resnet50/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/resnet50/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /Vision/classification/image/resnext50_32x4d/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="./resnext50_32x4d_oneflow_model" 4 | IMAGE_PATH="data/fish.jpg" 5 | 6 | if [ ! -d "data" ]; then 7 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 8 | tar zxf data.tar.gz 9 | fi 10 | 11 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 12 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/resnext50_32x4d/resnext50_32x4d_oneflow_model.tar.gz 13 | tar -xzvf resnext50_32x4d_oneflow_model.tar.gz 14 | fi 15 | 16 | python3 infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 17 | -------------------------------------------------------------------------------- /Vision/classification/image/resnext50_32x4d/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/resnext50_32x4d/models/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/resnext50_32x4d/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | Pillow 4 | -------------------------------------------------------------------------------- /Vision/classification/image/resnext50_32x4d/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="ofrecord" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 6 | tar zxf imagenette_ofrecord.tar.gz 7 | fi 8 | 9 | CHECKPOINT_PATH="checkpoints" 10 | if [ ! -d "$CHECKPOINT_PATH" ]; then 11 | mkdir $CHECKPOINT_PATH 12 | fi 13 | 14 | LEARNING_RATE=0.001 15 | MOM=0.9 16 | EPOCH=20 17 | TRAIN_BATCH_SIZE=16 18 | VAL_BATCH_SIZE=16 19 | 20 | # LOAD PREVIOUS CHECKPOINT 21 | # LOAD_CHECKPOINT="/PATH/TO/CHECKPOINT" 22 | 23 | python3 train.py \ 24 | --save_checkpoint_path $CHECKPOINT_PATH \ 25 | --ofrecord_path $OFRECORD_PATH \ 26 | --learning_rate $LEARNING_RATE \ 27 | --mom $MOM \ 28 | --epochs $EPOCH \ 29 | --train_batch_size $TRAIN_BATCH_SIZE \ 30 | --val_batch_size $VAL_BATCH_SIZE \ 31 | # --load_checkpoint $LOAD_CHECKPOINT 32 | 33 | 34 | -------------------------------------------------------------------------------- /Vision/classification/image/resnext50_32x4d/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/resnext50_32x4d/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/resnext50_32x4d/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /Vision/classification/image/scnet/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="./scnet_oneflow_model" 4 | IMAGE_PATH="data/img_red.png" 5 | 6 | if [ ! -f "$IMAGE_PATH" ]; then 7 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/models/scnet/data.zip 8 | unzip data.zip 9 | fi 10 | 11 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 12 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/scnet/scnet_oneflow_model.zip 13 | unzip scnet_oneflow_model.zip 14 | fi 15 | 16 | python3 infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 17 | -------------------------------------------------------------------------------- /Vision/classification/image/scnet/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | Pillow -------------------------------------------------------------------------------- /Vision/classification/image/scnet/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="./ofrecord/hustcolor" 4 | 5 | if [ ! -d "$OFRECORD_PATH" ]; then 6 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/models/scnet/ofrecord.zip 7 | unzip ofrecord.zip 8 | fi 9 | 10 | CHECKPOINT_PATH="checkpoints" 11 | if [ ! -d "$CHECKPOINT_PATH" ]; then 12 | mkdir $CHECKPOINT_PATH 13 | fi 14 | 15 | LEARNING_RATE=0.001 16 | MOM=0.9 17 | EPOCH=20 18 | TRAIN_BATCH_SIZE=16 19 | VAL_BATCH_SIZE=16 20 | 21 | # LOAD PREVIOUS CHECKPOINT 22 | # LOAD_CHECKPOINT="/PATH/TO/CHECKPOINT" 23 | 24 | python train.py \ 25 | --save_checkpoint_path $CHECKPOINT_PATH \ 26 | --ofrecord_path $OFRECORD_PATH \ 27 | --learning_rate $LEARNING_RATE \ 28 | --mom $MOM \ 29 | --epochs $EPOCH \ 30 | --train_batch_size $TRAIN_BATCH_SIZE \ 31 | --val_batch_size $VAL_BATCH_SIZE \ 32 | # --load_checkpoint $LOAD_CHECKPOINT 33 | 34 | 35 | -------------------------------------------------------------------------------- /Vision/classification/image/scnet/utils/clsidx_to_labels.py: -------------------------------------------------------------------------------- 1 | clsidx_2_labels = { 2 | 0: "black", 3 | 1: "blue", 4 | 2: "cyan", 5 | 3: "gray", 6 | 4: "green", 7 | 5: "red", 8 | 6: "white", 9 | 7: "yellow", 10 | } 11 | -------------------------------------------------------------------------------- /Vision/classification/image/shufflenetv2/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="shufflenet_imagenet_pretrain_model/" 4 | MODEL="shufflenetv2_x1.0" #can be one of shufflenetv2_x0.5, shufflenetv2_x1.0 5 | IMAGE_PATH="data/tiger.jpg" 6 | 7 | if [ ! -d "data" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 9 | tar zxf data.tar.gz 10 | fi 11 | 12 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 13 | mkdir ${PRETRAIN_MODEL_PATH} 14 | fi 15 | 16 | if [ ! -d "${PRETRAIN_MODEL_PATH}oneflow_${MODEL}" ]; then 17 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/shufflenetv2/oneflow_${MODEL}.zip 18 | unzip oneflow_${MODEL}.zip -d ${PRETRAIN_MODEL_PATH} 19 | fi 20 | 21 | python3 infer.py --model_path ${PRETRAIN_MODEL_PATH}oneflow_${MODEL} --image_path $IMAGE_PATH --model $MODEL 22 | -------------------------------------------------------------------------------- /Vision/classification/image/shufflenetv2/requirements.txt: -------------------------------------------------------------------------------- 1 | matplotlib 2 | numpy 3 | Pillow 4 | -------------------------------------------------------------------------------- /Vision/classification/image/shufflenetv2/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="./ofrecord" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 6 | tar zxf imagenette_ofrecord.tar.gz 7 | fi 8 | 9 | CHECKPOINT_PATH="checkpoints" 10 | if [ ! -d "$CHECKPOINT_PATH" ]; then 11 | mkdir $CHECKPOINT_PATH 12 | fi 13 | 14 | LEARNING_RATE=0.001 15 | MOM=0.9 16 | EPOCH=1000 17 | TRAIN_BATCH_SIZE=16 18 | VAL_BATCH_SIZE=16 19 | MODEL=shufflenetv2_x0.5 20 | 21 | # LOAD PREVIOUS CHECKPOINT 22 | # LOAD_CHECKPOINT=$CHECKPOINT_PATH/epoch_10_val_acc_0.230020 23 | 24 | python3 train.py \ 25 | --save_checkpoint_path $CHECKPOINT_PATH \ 26 | --ofrecord_path $OFRECORD_PATH \ 27 | --learning_rate $LEARNING_RATE \ 28 | --mom $MOM \ 29 | --epochs $EPOCH \ 30 | --train_batch_size $TRAIN_BATCH_SIZE \ 31 | --val_batch_size $VAL_BATCH_SIZE \ 32 | --model $MODEL \ 33 | #--load_checkpoint $LOAD_CHECKPOINT 34 | -------------------------------------------------------------------------------- /Vision/classification/image/shufflenetv2/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/shufflenetv2/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/shufflenetv2/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /Vision/classification/image/swin_transformer/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="./swin_tiny_patch4_window7_224_oneflow_model" 4 | IMAGE_PATH="data/fish.jpg" 5 | # IMAGE_PATH="data/tiger.jpg" 6 | # IMAGE_PATH="data/ILSVRC2012_val_00020287.JPEG" 7 | 8 | if [ ! -d "data" ]; then 9 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 10 | tar zxf data.tar.gz 11 | fi 12 | 13 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 14 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/swin_transformer/swin_tiny_patch4_window7_224_oneflow_model.tar.gz 15 | tar -xzvf swin_tiny_patch4_window7_224_oneflow_model.tar.gz 16 | fi 17 | 18 | python3 infer.py --model_path $PRETRAIN_MODEL_PATH --image_path $IMAGE_PATH 19 | -------------------------------------------------------------------------------- /Vision/classification/image/swin_transformer/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | Pillow 4 | -------------------------------------------------------------------------------- /Vision/classification/image/swin_transformer/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="ofrecord" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 6 | tar zxf imagenette_ofrecord.tar.gz 7 | fi 8 | 9 | CHECKPOINT_PATH="checkpoints" 10 | if [ ! -d "$CHECKPOINT_PATH" ]; then 11 | mkdir $CHECKPOINT_PATH 12 | fi 13 | 14 | LEARNING_RATE=0.001 15 | MOM=0.9 16 | EPOCH=20 17 | TRAIN_BATCH_SIZE=16 18 | VAL_BATCH_SIZE=16 19 | 20 | 21 | python3 train.py \ 22 | --save_checkpoint_path $CHECKPOINT_PATH \ 23 | --ofrecord_path $OFRECORD_PATH \ 24 | --learning_rate $LEARNING_RATE \ 25 | --mom $MOM \ 26 | --epochs $EPOCH \ 27 | --train_batch_size $TRAIN_BATCH_SIZE \ 28 | --val_batch_size $VAL_BATCH_SIZE \ 29 | # --load_checkpoint $LOAD_CHECKPOINT 30 | -------------------------------------------------------------------------------- /Vision/classification/image/swin_transformer/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/swin_transformer/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/swin_transformer/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /Vision/classification/image/vgg/README.md: -------------------------------------------------------------------------------- 1 | # VGG 2 | 3 | This repo is based on: https://github.com/pytorch/vision/blob/master/torchvision/models/vgg.py 4 | 5 | ## Inference on Single Image 6 | 7 | ```bash 8 | bash infer.sh 9 | ``` 10 | 11 | #### Download Ofrecord 12 | 13 | ```bash 14 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 15 | tar zxf imagenette_ofrecord.tar.gz 16 | ``` 17 | 18 | ### Run Oneflow Training script 19 | 20 | ```bash 21 | bash train_oneflow.sh 22 | ``` 23 | 24 | -------------------------------------------------------------------------------- /Vision/classification/image/vgg/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="vgg_imagenet_pretrain_model/" 4 | MODEL="vgg19_bn" #choose from vgg16, vgg16_bn, vgg19, vgg19_bn 5 | 6 | # IMAGE_PATH="data/fish.jpg" 7 | IMAGE_PATH="data/tiger.jpg" 8 | # IMAGE_PATH="data/ILSVRC2012_val_00020287.JPEG" 9 | 10 | if [ ! -d "data" ]; then 11 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/data.tar.gz 12 | tar zxf data.tar.gz 13 | fi 14 | 15 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 16 | mkdir ${PRETRAIN_MODEL_PATH} 17 | fi 18 | 19 | if [ ! -d "${PRETRAIN_MODEL_PATH}${MODEL}_oneflow_model" ]; then 20 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/vgg_models/${MODEL}_oneflow_model.tar.gz 21 | tar zxf ${MODEL}_oneflow_model.tar.gz --directory ${PRETRAIN_MODEL_PATH} 22 | fi 23 | 24 | python3 infer.py --model_path ${PRETRAIN_MODEL_PATH}${MODEL}_oneflow_model --image_path $IMAGE_PATH --model $MODEL 25 | -------------------------------------------------------------------------------- /Vision/classification/image/vgg/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/vgg/models/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/vgg/train_oneflow.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="ofrecord" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/imagenette_ofrecord.tar.gz 6 | tar zxf imagenette_ofrecord.tar.gz 7 | fi 8 | 9 | CHECKPOINT_PATH="checkpoints" 10 | if [ ! -d "$CHECKPOINT_PATH" ]; then 11 | mkdir $CHECKPOINT_PATH 12 | fi 13 | 14 | LEARNING_RATE=0.001 15 | MOM=0.9 16 | EPOCH=1000 17 | TRAIN_BATCH_SIZE=16 18 | VAL_BATCH_SIZE=16 19 | MODEL=vgg16_bn 20 | 21 | # LOAD PREVIOUS CHECKPOINT 22 | # LOAD_CHECKPOINT=$CHECKPOINT_PATH/epoch_10_val_acc_0.230020 23 | 24 | python3 train_oneflow.py \ 25 | --save_checkpoint_path $CHECKPOINT_PATH \ 26 | --ofrecord_path $OFRECORD_PATH \ 27 | --learning_rate $LEARNING_RATE \ 28 | --mom $MOM \ 29 | --epochs $EPOCH \ 30 | --train_batch_size $TRAIN_BATCH_SIZE \ 31 | --val_batch_size $VAL_BATCH_SIZE \ 32 | --model $MODEL \ 33 | #--load_checkpoint $LOAD_CHECKPOINT 34 | 35 | 36 | -------------------------------------------------------------------------------- /Vision/classification/image/vgg/utils/Figure_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/vgg/utils/Figure_1.png -------------------------------------------------------------------------------- /Vision/classification/image/vgg/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/classification/image/vgg/utils/__init__.py -------------------------------------------------------------------------------- /Vision/classification/image/vgg/utils/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | of_losses = [] 5 | torch_losses = [] 6 | 7 | with open("of_losses.txt", "r") as lines: 8 | for line in lines: 9 | line = line.strip() 10 | of_losses.append(float(line)) 11 | 12 | with open("torch_losses.txt", "r") as lines: 13 | for line in lines: 14 | line = line.strip() 15 | torch_losses.append(float(line)) 16 | 17 | 18 | indes = [i for i in range(len(of_losses))] 19 | 20 | 21 | plt.plot(indes, of_losses, label="oneflow") 22 | plt.plot(indes, torch_losses, label="pytorch") 23 | 24 | plt.xlabel("iter - axis") 25 | # Set the y axis label of the current axis. 26 | plt.ylabel("loss - axis") 27 | # Set a title of the current axes. 28 | plt.title("compare ") 29 | # show a legend on the plot 30 | plt.legend() 31 | # Display a figure. 32 | plt.show() 33 | -------------------------------------------------------------------------------- /Vision/classification/video/TSN/README.md: -------------------------------------------------------------------------------- 1 | # TSN 2 | 3 | This repo provides one method for Person Action Recognition task. 4 | 5 | ## Get started 6 | 7 | ```bash 8 | pip3 install -r requirements.txt 9 | ``` 10 | 11 | ## Data preparation 12 | 13 | We train and evaluate our models on Kinetics400 dataset. Please refer to (https://github.com/open-mmlab/mmaction/tree/master/data_tools/kinetics400) for data prepration. 14 | 15 | Download the mini_dataset to evaluate the model. 16 | 17 | ## Training 18 | 19 | ```bash 20 | bash train.sh 21 | ``` 22 | Our model is trained using ResNet50 as backbones 23 | 24 | ## Evaluating 25 | 26 | ```bash 27 | bash infer.sh 28 | ``` 29 | 30 | ## Accuracy 31 | 32 | oneflow torch 33 | top1 acc 0.6373 0.6373 34 | top5 acc 0.6785 0.6785 35 | -------------------------------------------------------------------------------- /Vision/classification/video/TSN/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | TSN_MODEL_PATH="tsn_model_oneflow" 4 | DATASET_PATH="./data" 5 | 6 | if [ ! -d "$DATASET_PATH" ]; then 7 | mkdir data 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/TSN/kinetics400.zip 9 | unzip -d ./data kinetics400.zip 10 | fi 11 | 12 | if [ ! -d "$TSN_MODEL_PATH" ]; then 13 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/action_recognition/tsn_model_oneflow.zip 14 | unzip tsn_model_oneflow.zip 15 | fi 16 | 17 | python3 test_recognizer.py --checkpoint $TSN_MODEL_PATH --data_dir $DATASET_PATH 18 | -------------------------------------------------------------------------------- /Vision/classification/video/TSN/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | PIL 3 | -------------------------------------------------------------------------------- /Vision/classification/video/TSN/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="resnet50_imagenet_pretrain_model" 4 | DATASET_PATH="./data" 5 | TRAIN_DATASET_PATH="./data/kinetics400/rawframes_train" 6 | SAVE_PATH="./save_path" 7 | 8 | if [ ! -d "$TRAIN_DATASET_PATH" ]; then 9 | echo "Error! The training data set is empty! Please refer to (https://github.com/open-mmlab/mmaction/tree/master/data_tools/kinetics400) for data prepration." 10 | exit 11 | fi 12 | 13 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 14 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/action_recognition/resnet50_imagenet_pretrain_model.zip 15 | unzip resnet50_imagenet_pretrain_model.zip 16 | fi 17 | 18 | if [ ! -d "$SAVE_PATH" ]; then 19 | mkdir save_path 20 | fi 21 | 22 | python3 train_recognizer.py --pretrained $PRETRAIN_MODEL_PATH --data_dir $DATASET_PATH --save_checkpoint_path $SAVE_PATH 23 | -------------------------------------------------------------------------------- /Vision/classification/video/TSN/tsn/models/simple_consensus.py: -------------------------------------------------------------------------------- 1 | import oneflow.nn as nn 2 | 3 | 4 | class SimpleConsensus(nn.Module): 5 | def __init__(self, consensus_type, dim=1): 6 | super(SimpleConsensus, self).__init__() 7 | assert consensus_type in ["avg"] 8 | self.consensus_type = consensus_type 9 | self.dim = dim 10 | 11 | def init_weights(self): 12 | pass 13 | 14 | def forward(self, input): 15 | if self.consensus_type == "avg": 16 | output = input.mean(dim=self.dim, keepdim=True) 17 | else: 18 | return None 19 | return output 20 | -------------------------------------------------------------------------------- /Vision/classification/video/TSN/tsn/models/simple_spatial_module.py: -------------------------------------------------------------------------------- 1 | import oneflow.nn as nn 2 | 3 | 4 | class SimpleSpatialModule(nn.Module): 5 | def __init__(self, spatial_type="avg", spatial_size=7): 6 | super(SimpleSpatialModule, self).__init__() 7 | 8 | assert spatial_type in ["avg"] 9 | self.spatial_type = spatial_type 10 | 11 | self.spatial_size = ( 12 | spatial_size 13 | if not isinstance(spatial_size, int) 14 | else (spatial_size, spatial_size) 15 | ) 16 | 17 | if self.spatial_type == "avg": 18 | self.op = nn.AvgPool2d(self.spatial_size, stride=1, padding=0) 19 | 20 | def init_weights(self): 21 | pass 22 | 23 | def forward(self, input): 24 | return self.op(input) 25 | -------------------------------------------------------------------------------- /Vision/classification/video/TSN/tsn/utils/checkpoint.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | 3 | 4 | def load_checkpoint( 5 | model, path_to_checkpoint, 6 | ): 7 | """ 8 | Load the checkpoint from the given file. If inflation is True, inflate the 9 | 2D Conv weights from the checkpoint to 3D Conv. 10 | Args: 11 | path_to_checkpoint (string): path to the checkpoint to load. 12 | model (model): model to load the weights from the checkpoint. 13 | """ 14 | checkpoint = flow.load(path_to_checkpoint) 15 | 16 | if not isinstance(checkpoint, dict): 17 | raise RuntimeError( 18 | "No state_dict found in checkpoint file {}".format(path_to_checkpoint) 19 | ) 20 | 21 | # get state_dict from checkpoint 22 | if "state_dict" in checkpoint: 23 | state_dict = checkpoint["state_dict"] 24 | else: 25 | state_dict = checkpoint 26 | 27 | model.load_state_dict(state_dict) 28 | 29 | return model 30 | -------------------------------------------------------------------------------- /Vision/detection/CSRNet/requirement.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | cv2 3 | h5py 4 | pillow -------------------------------------------------------------------------------- /Vision/detection/CSRNet/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="vgg_imagenet_pretrain_model/" 4 | MODEL_PATH="checkpoint/" 5 | Data_PATH="dataset" 6 | 7 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 8 | mkdir ${PRETRAIN_MODEL_PATH} 9 | fi 10 | 11 | 12 | if [ ! -d "${PRETRAIN_MODEL_PATH}vgg16_oneflow_model" ]; then 13 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/classification/vgg_models/vgg16_oneflow_model.tar.gz 14 | tar zxf vgg16_oneflow_model.tar.gz --directory ${PRETRAIN_MODEL_PATH} 15 | fi 16 | 17 | if [ ! -d "$MODEL_PATH" ]; then 18 | mkdir ${MODEL_PATH} 19 | fi 20 | 21 | if [ ! -d "${Data_PATH}" ]; then 22 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/models/CSRNet/Shanghai_dataset.zip 23 | unzip Shanghai_dataset.zip 24 | mv Shanghai_dataset ${Data_PATH} 25 | fi 26 | 27 | python3 train.py part_A_train.json part_A_val.json kk/ 0 0 28 | -------------------------------------------------------------------------------- /Vision/gan/DCGAN/check/check.sh: -------------------------------------------------------------------------------- 1 | 2 | set -aux 3 | 4 | DATA_PATH="mnist" 5 | if [ ! -d "$DATA_PATH" ]; then 6 | wget https://oneflow-static.oss-cn-beijing.aliyuncs.com/Dataset/mnist.zip 7 | unzip mnist.zip 8 | fi 9 | 10 | BASE_PATH='./dcgan' 11 | LEARNING_RATE=0.0001 12 | EPOCH=1 13 | BATCH_SIZE=256 14 | SAVE=True 15 | 16 | python3 check/check.py \ 17 | -lr $LEARNING_RATE \ 18 | -e $EPOCH \ 19 | --batch_size $BATCH_SIZE \ 20 | --path $BASE_PATH \ 21 | --save $SAVE \ 22 | --data_dir $DATA_PATH \ 23 | -------------------------------------------------------------------------------- /Vision/gan/DCGAN/eager/train.sh: -------------------------------------------------------------------------------- 1 | 2 | set -aux 3 | 4 | DATA_PATH="mnist" 5 | if [ ! -d "$DATA_PATH" ]; then 6 | wget https://oneflow-static.oss-cn-beijing.aliyuncs.com/Dataset/mnist.zip 7 | unzip mnist.zip 8 | fi 9 | 10 | 11 | BASE_PATH='./dcgan' 12 | LEARNING_RATE=0.0001 13 | EPOCH=100 14 | BATCH_SIZE=256 15 | SAVE=True 16 | # LOAD_CHECKPOINT= 17 | 18 | python3 eager/train.py \ 19 | -lr $LEARNING_RATE \ 20 | -e $EPOCH \ 21 | --batch_size $BATCH_SIZE \ 22 | --path $BASE_PATH \ 23 | --save $SAVE \ 24 | --data_dir $DATA_PATH \ 25 | # --load $LOAD_CHECKPOINT 26 | -------------------------------------------------------------------------------- /Vision/gan/DCGAN/graph/train.sh: -------------------------------------------------------------------------------- 1 | 2 | set -aux 3 | 4 | DATA_PATH="mnist" 5 | if [ ! -d "$DATA_PATH" ]; then 6 | wget https://oneflow-static.oss-cn-beijing.aliyuncs.com/Dataset/mnist.zip 7 | unzip mnist.zip 8 | fi 9 | 10 | 11 | BASE_PATH='./dcgan' 12 | LEARNING_RATE=0.0001 13 | EPOCH=100 14 | BATCH_SIZE=256 15 | SAVE=True 16 | # LOAD_CHECKPOINT= 17 | 18 | python3 graph/train.py \ 19 | -lr $LEARNING_RATE \ 20 | -e $EPOCH \ 21 | --batch_size $BATCH_SIZE \ 22 | --path $BASE_PATH \ 23 | --save $SAVE \ 24 | --data_dir $DATA_PATH \ 25 | # --load $LOAD_CHECKPOINT 26 | -------------------------------------------------------------------------------- /Vision/gan/DCGAN/test/test_of_dcgan.sh: -------------------------------------------------------------------------------- 1 | 2 | set -aux 3 | 4 | MODEL_PATH="g_99" 5 | SAVE_PATH="test_images.png" 6 | 7 | 8 | if [ ! -d "$MODEL_PATH" ]; then 9 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/gan/DCGAN_g.zip 10 | unzip DCGAN_g.zip 11 | fi 12 | 13 | python3 test/test_of_dcgan.py --model_path $MODEL_PATH --save_path $SAVE_PATH 14 | -------------------------------------------------------------------------------- /Vision/gan/DCGAN/test/test_of_dcgan_graph.sh: -------------------------------------------------------------------------------- 1 | 2 | set -aux 3 | 4 | MODEL_PATH="g_99_graph/" 5 | SAVE_PATH="test_images.png" 6 | 7 | 8 | if [ ! -d "$MODEL_PATH" ]; then 9 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/DCGAN/g_99_graph.tar.gz 10 | tar -zxf g_99_graph.tar.gz 11 | fi 12 | 13 | python3 test/test_of_dcgan.py --model_path $MODEL_PATH --save_path $SAVE_PATH 14 | -------------------------------------------------------------------------------- /Vision/gan/DCGAN/test_images.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/gan/DCGAN/test_images.png -------------------------------------------------------------------------------- /Vision/gan/SRGAN/README.md: -------------------------------------------------------------------------------- 1 | # SRGAN 2 | SRGAN, [Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network](https://arxiv.org/abs/1609.04802), is an image super resolution model. The code in lazy mode in [here](https://github.com/Oneflow-Inc/oneflow_vision_model/tree/main/SRGAN). 3 | ## Train 4 | ``` 5 | bash train_of_srgan.sh 6 | ``` 7 | 8 | The train, val dataset of [VOC2012](http://host.robots.ox.ac.uk:8080/pascal/VOC/voc2012/index.html) and pretrained model for perceptual loss will be downloaded to './data/VOC' and './vgg_imagenet_pretrain_model' folder, respectively. 9 | 10 | 11 | ## Test Single Image 12 | ``` 13 | bash test_of_srgan.sh 14 | ``` 15 | The trained model will be automatically download. 16 | 17 | Inference results 18 | ![](results.png) 19 | -------------------------------------------------------------------------------- /Vision/gan/SRGAN/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | scikit_image 3 | tqdm 4 | Pillow 5 | scikit_image 6 | -------------------------------------------------------------------------------- /Vision/gan/SRGAN/results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/gan/SRGAN/results.png -------------------------------------------------------------------------------- /Vision/gan/SRGAN/test_of_srgan.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | DATA_PATH='data/' 4 | IMAGE_NAME='monarch' 5 | MODEL_PATH="SRGAN_netG_epoch_4_99" 6 | 7 | if [ ! -d $DATA_PATH ]; then 8 | mkdir ${DATA_PATH} 9 | fi 10 | if [ ! -f $DATA_PATH$IMAGE_NAME'.png' ]; then 11 | wget https://oneflow-static.oss-cn-beijing.aliyuncs.com/train_data_zjlab/monarch.png 12 | mv $IMAGE_NAME'.png' $DATA_PATH 13 | fi 14 | if [ ! -f $DATA_PATH$IMAGE_NAME'x4.png' ]; then 15 | wget https://oneflow-static.oss-cn-beijing.aliyuncs.com/train_data_zjlab/monarchx4.png 16 | mv $IMAGE_NAME'x4.png' $DATA_PATH 17 | fi 18 | 19 | 20 | if [ ! -d "$MODEL_PATH" ]; then 21 | wget https://oneflow-static.oss-cn-beijing.aliyuncs.com/train_data_zjlab/SRGAN_netG_epoch_4_99.zip 22 | unzip SRGAN_netG_epoch_4_99.zip 23 | fi 24 | 25 | python3 test_of_srgan.py --image_path $DATA_PATH$IMAGE_NAME'x4.png' --hr_path $DATA_PATH$IMAGE_NAME'.png' --model_path $MODEL_PATH --save_image $DATA_PATH$IMAGE_NAME'-oneflow.png' 26 | -------------------------------------------------------------------------------- /Vision/gan/cycleGAN/README.md: -------------------------------------------------------------------------------- 1 | ### Download dataset 2 | 3 | ```bash 4 | bash download.sh 5 | ``` 6 | 7 | You can customize the dataset by modifying download.sh provided by the original [CycleGAN repo](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix.git). 8 | 9 | 10 | 11 | ### Train 12 | 13 | ```bash 14 | bash train.sh 15 | ``` 16 | 17 | You can customize the train settings by modifying train.sh 18 | 19 | 20 | 21 | ### Infer 22 | 23 | ```bash 24 | bash infer.sh 25 | ``` 26 | 27 | You can customize infer settings by modifying infer.sh 28 | 29 | 30 | 31 | ### Results 32 | 33 | We have trained the following three models for about 100 epochs each. 34 | 35 | #### apple2orange 36 | 37 | ![Merged_document](https://i.loli.net/2021/07/26/7zHAXdNhtwec3TP.jpg) 38 | 39 | #### summer2winter_yosemite 40 | 41 | ![Merged_document (1)](https://i.loli.net/2021/07/26/2fND8VIeqbLat3k.jpg) 42 | 43 | #### horse2zebra 44 | 45 | ![Merged_document (2)](https://i.loli.net/2021/07/26/jtknahxdNPJswyH.jpg) -------------------------------------------------------------------------------- /Vision/gan/cycleGAN/requirements.txt: -------------------------------------------------------------------------------- 1 | opencv_python==4.2.0.34 2 | numpy==1.20.1 3 | -------------------------------------------------------------------------------- /Vision/gan/pix2pix/README.md: -------------------------------------------------------------------------------- 1 | # Pix2pix 2 | 3 | ## Introduction 4 | Pix2Pix is a conditional image generation method, our code is inspired by [TensorFlow Tutorial](https://tensorflow.google.cn/tutorials/generative/pix2pix) and github repository[ pytorch-CycleGAN-and-pix2pix](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix). 5 | 6 | ## Installation 7 | oneflow >= 0.4.0 8 | 9 | ## Prepare data 10 | If you want to run train and test on small dataset (e.g., Facades, about 30.9M), running the train.sh file automatically download this dataset in "./data/facades". 11 | 12 | ## Train 13 | ``` 14 | bash train.sh 15 | ``` 16 | 17 | ## Download pretrained model 18 | If you just want to run test, we provide a pretrained model. You can run the infer.sh file and the pretrained model will be downloaded automatically. 19 | 20 | ## Test 21 | ``` 22 | bash infer.sh 23 | ``` 24 | -------------------------------------------------------------------------------- /Vision/gan/pix2pix/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | MODEL_PATH='pix2pix_g_200' 3 | IMAGE_PATH='./data/facades/test/1.jpg' 4 | 5 | if [ ! -d "$MODEL_PATH" ]; then 6 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/gan/pix2pix_g_200.zip 7 | unzip pix2pix_g_200.zip 8 | rm pix2pix_g_200.zip 9 | fi 10 | 11 | python3 infer.py \ 12 | --model_path $MODEL_PATH \ 13 | --image_path $IMAGE_PATH \ 14 | -------------------------------------------------------------------------------- /Vision/gan/pix2pix/requirements.txt: -------------------------------------------------------------------------------- 1 | matplotlib 2 | numpy 3 | Pillow -------------------------------------------------------------------------------- /Vision/gan/pix2pix/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | DATASET_PATH="./data/facades/" 4 | if [ ! -d "$DATASET_PATH" ]; then 5 | mkdir -p ./data/ 6 | wget -N http://efrosgans.eecs.berkeley.edu/pix2pix/datasets/facades.tar.gz -O ./data/facades.tar.gz 7 | tar -zxvf ./data/facades.tar.gz -C ./data/ 8 | rm ./data/facades.tar.gz 9 | fi 10 | 11 | LEARNING_RATE=2e-4 12 | EPOCH=200 13 | TRAIN_BATCH_SIZE=1 14 | TRAIN_PATH="./of_pix2pix" 15 | 16 | python3 train.py \ 17 | -lr $LEARNING_RATE \ 18 | -e $EPOCH \ 19 | --batch_size $TRAIN_BATCH_SIZE \ 20 | --path $TRAIN_PATH \ -------------------------------------------------------------------------------- /Vision/oneflow_face/backbones/__init__.py: -------------------------------------------------------------------------------- 1 | from .ir_resnet import iresnet18, iresnet34, iresnet50, iresnet100, iresnet200 2 | 3 | 4 | def get_model(name, **kwargs): 5 | if name == "r18": 6 | return iresnet18(False, **kwargs) 7 | elif name == "r34": 8 | return iresnet34(False, **kwargs) 9 | elif name == "r50": 10 | return iresnet50(False, **kwargs) 11 | elif name == "r100": 12 | return iresnet100(False, **kwargs) 13 | elif name == "r200": 14 | return iresnet200(False, **kwargs) 15 | else: 16 | raise ValueError() 17 | -------------------------------------------------------------------------------- /Vision/oneflow_face/configs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/oneflow_face/configs/__init__.py -------------------------------------------------------------------------------- /Vision/oneflow_face/configs/glint360k_mbf.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | 3 | # make training faster 4 | # our RAM is 256G 5 | # mount -t tmpfs -o size=140G tmpfs /train_tmp 6 | 7 | config = edict() 8 | config.loss = "cosface" 9 | config.network = "mbf" 10 | config.resume = False 11 | config.output = None 12 | config.embedding_size = 512 13 | config.partial_fc = 1 14 | config.sample_rate = 0.1 15 | config.model_parallel = True 16 | config.fp16 = True 17 | config.momentum = 0.9 18 | config.weight_decay = 2e-4 19 | config.batch_size = 128 20 | config.lr = 0.1 # batch size is 512 21 | 22 | config.dataset = "glint360k" 23 | config.ofrecord_path = "/train_tmp/glint360k/" 24 | config.ofrecord_part_num = 200 25 | config.num_classes = 360232 26 | config.num_image = 17091657 27 | config.num_epoch = 20 28 | config.warmup_epoch = -1 29 | config.decay_epoch = [8, 12, 15, 18] 30 | config.val_targets = ["lfw", "cfp_fp", "agedb_30"] 31 | -------------------------------------------------------------------------------- /Vision/oneflow_face/configs/glint360k_r100.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | 3 | # make training faster 4 | # our RAM is 256G 5 | # mount -t tmpfs -o size=140G tmpfs /train_tmp 6 | 7 | config = edict() 8 | config.loss = "cosface" 9 | config.network = "r100" 10 | config.resume = False 11 | config.output = None 12 | config.embedding_size = 512 13 | config.partial_fc = 1 14 | config.sample_rate = 0.1 15 | config.model_parallel = True 16 | config.fp16 = True 17 | config.momentum = 0.9 18 | config.weight_decay = 5e-4 19 | config.batch_size = 128 20 | config.lr = 0.1 # batch size is 512 21 | 22 | 23 | config.dataset = "glint360k" 24 | config.ofrecord_path = "/train_tmp/glint360k/" 25 | config.ofrecord_part_num = 200 26 | config.num_classes = 360232 27 | config.num_image = 17091657 28 | config.num_epoch = 20 29 | config.warmup_epoch = -1 30 | config.decay_epoch = [8, 12, 15, 18] 31 | config.val_targets = ["lfw", "cfp_fp", "agedb_30"] 32 | -------------------------------------------------------------------------------- /Vision/oneflow_face/configs/glint360k_r18.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | 3 | # make training faster 4 | # our RAM is 256G 5 | # mount -t tmpfs -o size=140G tmpfs /train_tmp 6 | 7 | config = edict() 8 | config.loss = "cosface" 9 | config.network = "r18" 10 | config.resume = False 11 | config.output = None 12 | config.embedding_size = 512 13 | config.partial_fc = 1 14 | config.sample_rate = 0.1 15 | config.model_parallel = True 16 | config.fp16 = True 17 | config.momentum = 0.9 18 | config.weight_decay = 5e-4 19 | config.batch_size = 128 20 | config.lr = 0.1 # batch size is 512 21 | 22 | config.dataset = "glint360k" 23 | config.ofrecord_path = "/train_tmp/glint360k/" 24 | config.ofrecord_part_num = 200 25 | config.num_classes = 360232 26 | config.num_image = 17091657 27 | config.num_epoch = 20 28 | config.warmup_epoch = -1 29 | config.decay_epoch = [8, 12, 15, 18] 30 | config.val_targets = ["lfw", "cfp_fp", "agedb_30"] 31 | -------------------------------------------------------------------------------- /Vision/oneflow_face/configs/glint360k_r34.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | 3 | # make training faster 4 | # our RAM is 256G 5 | # mount -t tmpfs -o size=140G tmpfs /train_tmp 6 | 7 | config = edict() 8 | config.loss = "cosface" 9 | config.network = "r34" 10 | config.resume = False 11 | config.output = None 12 | config.embedding_size = 512 13 | config.partial_fc = 1 14 | config.sample_rate = 0.1 15 | config.model_parallel = True 16 | config.fp16 = True 17 | config.momentum = 0.9 18 | config.weight_decay = 5e-4 19 | config.batch_size = 128 20 | config.lr = 0.1 # batch size is 512 21 | 22 | config.dataset = "glint360k" 23 | config.ofrecord_path = "/train_tmp/glint360k/" 24 | config.ofrecord_part_num = 200 25 | config.num_classes = 360232 26 | config.num_image = 17091657 27 | config.num_epoch = 20 28 | config.warmup_epoch = -1 29 | config.decay_epoch = [8, 12, 15, 18] 30 | config.val_targets = ["lfw", "cfp_fp", "agedb_30"] 31 | -------------------------------------------------------------------------------- /Vision/oneflow_face/configs/glint360k_r50.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | 3 | # make training faster 4 | # our RAM is 256G 5 | # mount -t tmpfs -o size=140G tmpfs /train_tmp 6 | 7 | config = edict() 8 | config.loss = "cosface" 9 | config.network = "r50" 10 | config.resume = False 11 | config.output = None 12 | config.embedding_size = 512 13 | config.partial_fc = 1 14 | config.sample_rate = 0.1 15 | config.model_parallel = True 16 | config.fp16 = True 17 | config.momentum = 0.9 18 | config.weight_decay = 5e-4 19 | config.batch_size = 128 20 | config.lr = 0.1 # batch size is 512 21 | 22 | config.dataset = "glint360k" 23 | config.ofrecord_path = "/train_tmp/glint360k/" 24 | config.ofrecord_part_num = 200 25 | config.num_classes = 360232 26 | config.num_image = 17091657 27 | config.num_epoch = 20 28 | config.warmup_epoch = -1 29 | config.decay_epoch = [8, 12, 15, 18] 30 | config.val_targets = ["lfw", "cfp_fp", "agedb_30"] 31 | -------------------------------------------------------------------------------- /Vision/oneflow_face/configs/ms1mv3_mbf.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | 3 | # make training faster 4 | # our RAM is 256G 5 | # mount -t tmpfs -o size=140G tmpfs /train_tmp 6 | 7 | config = edict() 8 | config.loss = "arcface" 9 | config.network = "mbf" 10 | config.resume = False 11 | config.output = None 12 | config.embedding_size = 512 13 | config.model_parallel = True 14 | config.partial_fc = 1 15 | config.sample_rate = 0.1 16 | config.fp16 = True 17 | config.momentum = 0.9 18 | config.weight_decay = 2e-4 19 | config.batch_size = 128 20 | config.lr = 0.1 # batch size is 512 21 | 22 | config.ofrecord_path = "/train_tmp/ms1m-retinaface-t1" 23 | config.ofrecord_part_num = 8 24 | config.num_classes = 93431 25 | config.num_image = 5179510 26 | config.num_epoch = 30 27 | config.warmup_epoch = -1 28 | config.decay_epoch = [10, 20, 25] 29 | config.val_targets = ["lfw", "cfp_fp", "agedb_30"] 30 | -------------------------------------------------------------------------------- /Vision/oneflow_face/configs/ms1mv3_r18.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | 3 | # make training faster 4 | # our RAM is 256G 5 | # mount -t tmpfs -o size=140G tmpfs /train_tmp 6 | 7 | config = edict() 8 | config.loss = "arcface" 9 | config.network = "r18" 10 | config.resume = False 11 | config.output = None 12 | config.embedding_size = 512 13 | config.model_parallel = True 14 | config.partial_fc = 1 15 | config.sample_rate = 0.1 16 | config.fp16 = True 17 | config.momentum = 0.9 18 | config.weight_decay = 5e-4 19 | config.batch_size = 128 20 | config.lr = 0.1 # batch size is 512 21 | 22 | config.ofrecord_path = "/train_tmp/ms1m-retinaface-t1" 23 | config.ofrecord_part_num = 8 24 | config.num_classes = 93431 25 | config.num_image = 5179510 26 | config.num_epoch = 25 27 | config.warmup_epoch = -1 28 | config.decay_epoch = [10, 16, 22] 29 | config.val_targets = ["lfw", "cfp_fp", "agedb_30"] 30 | -------------------------------------------------------------------------------- /Vision/oneflow_face/configs/ms1mv3_r34.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | 3 | # make training faster 4 | # our RAM is 256G 5 | # mount -t tmpfs -o size=140G tmpfs /train_tmp 6 | 7 | config = edict() 8 | config.loss = "arcface" 9 | config.network = "r34" 10 | config.resume = False 11 | config.output = None 12 | config.embedding_size = 512 13 | config.model_parallel = True 14 | config.partial_fc = 1 15 | config.sample_rate = 0.1 16 | config.fp16 = True 17 | config.momentum = 0.9 18 | config.weight_decay = 5e-4 19 | config.batch_size = 128 20 | config.lr = 0.1 # batch size is 512 21 | 22 | 23 | config.ofrecord_path = "/train_tmp/ms1m-retinaface-t1" 24 | config.ofrecord_part_num = 8 25 | config.num_classes = 93431 26 | config.num_image = 5179510 27 | config.num_epoch = 25 28 | config.warmup_epoch = -1 29 | config.decay_epoch = [10, 16, 22] 30 | config.val_targets = ["lfw", "cfp_fp", "agedb_30"] 31 | -------------------------------------------------------------------------------- /Vision/oneflow_face/configs/ms1mv3_r50.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | 3 | # make training faster 4 | # our RAM is 256G 5 | # mount -t tmpfs -o size=140G tmpfs /train_tmp 6 | 7 | config = edict() 8 | config.loss = "cosface" 9 | config.network = "r50" 10 | config.resume = False 11 | config.output = "partial_fc" 12 | config.embedding_size = 512 13 | config.model_parallel = True 14 | config.partial_fc = 0 15 | config.sample_rate = 0.1 16 | config.fp16 = True 17 | config.momentum = 0.9 18 | config.weight_decay = 5e-4 19 | config.batch_size = 128 20 | config.lr = 0.1 # batch size is 512 21 | 22 | 23 | config.ofrecord_path = "/train_tmp/ms1m-retinaface-t1/ofrecord/" 24 | config.ofrecord_part_num = 8 25 | config.num_classes = 93432 26 | config.num_image = 5179510 27 | config.num_epoch = 25 28 | config.warmup_epoch = -1 29 | config.decay_epoch = [10, 16, 22] 30 | config.val_targets = ["lfw", "cfp_fp", "agedb_30"] 31 | -------------------------------------------------------------------------------- /Vision/oneflow_face/configs/speed.py: -------------------------------------------------------------------------------- 1 | from easydict import EasyDict as edict 2 | 3 | # configs for test speed 4 | 5 | config = edict() 6 | config.loss = "arcface" 7 | config.network = "r50" 8 | config.resume = False 9 | config.output = None 10 | config.embedding_size = 512 11 | config.model_parallel = True 12 | config.sample_rate = 1.0 13 | config.fp16 = False 14 | config.momentum = 0.9 15 | config.weight_decay = 5e-4 16 | config.batch_size = 128 17 | config.lr = 0.1 # batch size is 512 18 | 19 | config.synthetic = True 20 | config.num_classes = 100000 21 | config.num_epoch = 30 22 | config.warmup_epoch = -1 23 | config.decay_epoch = [10, 16, 22] 24 | config.val_targets = [] 25 | -------------------------------------------------------------------------------- /Vision/oneflow_face/convert.sh: -------------------------------------------------------------------------------- 1 | 2 | python3 oneflow2onnx.py configs/ms1mv3_r50 --model_path /workdir/epoch_0 3 | -------------------------------------------------------------------------------- /Vision/oneflow_face/eval/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/oneflow_face/eval/__init__.py -------------------------------------------------------------------------------- /Vision/oneflow_face/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | matplotlib 3 | Pillow 4 | opencv-python 5 | scikit-learn 6 | scipy 7 | easydict -------------------------------------------------------------------------------- /Vision/oneflow_face/train_ddp.sh: -------------------------------------------------------------------------------- 1 | # set -aux 2 | 3 | MASTER_ADDR=127.0.0.1 4 | MASTER_PORT=17788 5 | DEVICE_NUM_PER_NODE=8 6 | NUM_NODES=1 7 | NODE_RANK=0 8 | 9 | 10 | export PYTHONUNBUFFERED=1 11 | echo PYTHONUNBUFFERED=$PYTHONUNBUFFERED 12 | export NCCL_LAUNCH_MODE=PARALLEL 13 | echo NCCL_LAUNCH_MODE=$NCCL_LAUNCH_MODE 14 | export NCCL_DEBUG=INFO 15 | export ONEFLOW_DEBUG_MODE=True 16 | 17 | 18 | NCCL_DEBUG=INFO \ 19 | python3 -m oneflow.distributed.launch \ 20 | --nproc_per_node $DEVICE_NUM_PER_NODE \ 21 | --nnodes $NUM_NODES \ 22 | --node_rank $NODE_RANK \ 23 | --master_addr $MASTER_ADDR \ 24 | --master_port $MASTER_PORT \ 25 | train.py configs/ms1mv3_r50.py 26 | -------------------------------------------------------------------------------- /Vision/oneflow_face/train_graph_distributed.sh: -------------------------------------------------------------------------------- 1 | # set -aux 2 | 3 | MASTER_ADDR=127.0.0.1 4 | MASTER_PORT=17788 5 | DEVICE_NUM_PER_NODE=8 6 | NUM_NODES=1 7 | NODE_RANK=0 8 | 9 | 10 | 11 | export PYTHONUNBUFFERED=1 12 | echo PYTHONUNBUFFERED=$PYTHONUNBUFFERED 13 | export NCCL_LAUNCH_MODE=PARALLEL 14 | echo NCCL_LAUNCH_MODE=$NCCL_LAUNCH_MODE 15 | #export NCCL_DEBUG=INFO 16 | export ONEFLOW_DEBUG_MODE=True 17 | 18 | 19 | #NCCL_DEBUG=INFO 20 | python3 -m oneflow.distributed.launch \ 21 | --nproc_per_node $DEVICE_NUM_PER_NODE \ 22 | --nnodes $NUM_NODES \ 23 | --node_rank $NODE_RANK \ 24 | --master_addr $MASTER_ADDR \ 25 | --master_port $MASTER_PORT \ 26 | train.py configs/ms1mv3_r50.py --graph 27 | -------------------------------------------------------------------------------- /Vision/oneflow_face/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/oneflow_face/utils/__init__.py -------------------------------------------------------------------------------- /Vision/oneflow_face/utils/utils_config.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | import os.path as osp 3 | 4 | 5 | def get_config(config_file): 6 | assert config_file.startswith( 7 | "configs/" 8 | ), "config file setting must start with configs/" 9 | temp_config_name = osp.basename(config_file) 10 | temp_module_name = osp.splitext(temp_config_name)[0] 11 | config = importlib.import_module("configs.base") 12 | cfg = config.config 13 | config = importlib.import_module("configs.%s" % temp_module_name) 14 | job_cfg = config.config 15 | cfg.update(job_cfg) 16 | if cfg.output is None: 17 | cfg.output = osp.join("work_dirs", temp_module_name) 18 | return cfg 19 | -------------------------------------------------------------------------------- /Vision/oneflow_face/val.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | python val.py configs/ms1mv3_r50 --model_path eager_test/epoch_0 4 | -------------------------------------------------------------------------------- /Vision/reid/BoT/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | REID_MODEL_PATH="reid_oneflow_model" 4 | DATASET_PATH="./datasets" 5 | 6 | 7 | if [ ! -d "$REID_MODEL_PATH" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/reid/reid_oneflow_model.zip 9 | unzip reid_oneflow_model.zip 10 | fi 11 | 12 | 13 | python3 reid.py --evaluate --load_weights $REID_MODEL_PATH --data_dir $DATASET_PATH 14 | -------------------------------------------------------------------------------- /Vision/reid/BoT/requirements.txt: -------------------------------------------------------------------------------- 1 | six 2 | scipy 3 | numpy 4 | oneflow 5 | Pillow 6 | -------------------------------------------------------------------------------- /Vision/reid/BoT/train.sh: -------------------------------------------------------------------------------- 1 | !#/bin/bash 2 | set -aux 3 | 4 | PRETRAIN_MODEL_PATH="resnet50_pretrained_model" 5 | DATASET_PATH="./datasets" 6 | 7 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 8 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/reid/resnet50_pretrained_model.zip 9 | unzip resnet50_pretrained_model.zip 10 | fi 11 | 12 | 13 | python3 reid.py --load_weights $PRETRAIN_MODEL_PATH --data_dir $DATASET_PATH 14 | -------------------------------------------------------------------------------- /Vision/reid/BoT/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/reid/BoT/utils/__init__.py -------------------------------------------------------------------------------- /Vision/segmentation/FODDet/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | opencv-python 3 | matplotlib 4 | albumentations 5 | tqdm -------------------------------------------------------------------------------- /Vision/segmentation/FODDet/test/test.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | PRETRAINED_WEIGHT="./UNetmodel" 5 | DATA_DIR="./CamVid" 6 | SAVE_PATH="./test_results" 7 | 8 | if [ ! -d "$PRETRAINED_WEIGHT" ]; then 9 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/seg/FODDET/UNetmodel.zip 10 | unzip UNetmodel.zip 11 | fi 12 | 13 | python test/test.py \ 14 | --pretrained_path $PRETRAINED_WEIGHT \ 15 | --data_dir $DATA_DIR \ 16 | --save_path $SAVE_PATH \ 17 | -------------------------------------------------------------------------------- /Vision/segmentation/FODDet/test/visualize.py: -------------------------------------------------------------------------------- 1 | import os 2 | import matplotlib.pyplot as plt 3 | 4 | 5 | def visualize(save_path, **images): 6 | """PLot images in one row.""" 7 | n = len(images) 8 | plt.figure(figsize=(16, 5)) 9 | for i, (name, image) in enumerate(images.items()): 10 | plt.subplot(1, n, i + 1) 11 | plt.xticks([]) 12 | plt.yticks([]) 13 | plt.title(" ".join(name.split("_")).title()) 14 | plt.imshow(image) 15 | plt.show() 16 | plt.savefig(save_path) 17 | -------------------------------------------------------------------------------- /Vision/segmentation/FODDet/train/train.sh: -------------------------------------------------------------------------------- 1 | export PYTHONPATH=$PWD:$PYTHONPATH 2 | set -aux 3 | 4 | OFRECORD_PATH="CamVid" 5 | if [ ! -d "$OFRECORD_PATH" ]; then 6 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/models/seg/FODDET/CamVid.zip 7 | unzip CamVid.zip 8 | fi 9 | 10 | 11 | LEARNING_RATE=0.001 12 | EPOCH=50 13 | TRAIN_BATCH_SIZE=8 14 | DATA_DIR="./CamVid" 15 | SAVE_PATH="./checkpoint" 16 | 17 | 18 | python3 train/train.py --data_dir $DATA_DIR \ 19 | --save_checkpoint_path $SAVE_PATH \ 20 | --learning_rate $LEARNING_RATE \ 21 | --epochs $EPOCH \ 22 | --train_batch_size $TRAIN_BATCH_SIZE \ 23 | -------------------------------------------------------------------------------- /Vision/segmentation/FaceSeg/infer.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | PRETRAIN_MODEL_PATH="linknet_oneflow_model" 4 | 5 | if [ ! -d "$PRETRAIN_MODEL_PATH" ]; then 6 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/model_zoo/cv/seg/linknet_oneflow_model.zip 7 | unzip linknet_oneflow_model.zip 8 | rm linknet_oneflow_model.zip 9 | fi 10 | 11 | SOURCE="./source1.avi" 12 | if [ ! -f "$SOURCE" ]; then 13 | wget https://oneflow-public.oss-cn-beijing.aliyuncs.com/datasets/models/seg/source1.avi 14 | fi 15 | 16 | python3 infer.py --model_path $PRETRAIN_MODEL_PATH -------------------------------------------------------------------------------- /Vision/segmentation/FaceSeg/models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/segmentation/FaceSeg/models/__init__.py -------------------------------------------------------------------------------- /Vision/segmentation/FaceSeg/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | Pillow 3 | opencv-contrib-pythonalbumentations 4 | albumentations 5 | -------------------------------------------------------------------------------- /Vision/segmentation/FaceSeg/train.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | LEARNING_RATE=0.001 4 | MOM=0.9 5 | EPOCH=50 6 | MODEL_PATH="./pretrained_resnet_oneflow_model" 7 | DATASET_PATH="./faceseg_data/" 8 | SAVE_MODEL_NAME="linknet_oneflow_model" 9 | # LOAD PREVIOUS CHECKPOINT 10 | # LOAD_CHECKPOINT="/PATH/TO/CHECKPOINT" 11 | 12 | if [ ! -d "$DATASET_PATH" ]; then 13 | wget https://oneflow-static.oss-cn-beijing.aliyuncs.com/train_data_zjlab/faceseg_data.zip 14 | mkdir faceseg_data 15 | unzip faceseg_data -d faceseg_data 16 | fi 17 | 18 | python3 train.py \ 19 | --learning_rate $LEARNING_RATE \ 20 | --mom $MOM \ 21 | --epochs $EPOCH \ 22 | --model_path $MODEL_PATH \ 23 | --dataset_path $DATASET_PATH \ 24 | --save_model_name $SAVE_MODEL_NAME \ 25 | # --load_checkpoint $LOAD_CHECKPOINT 26 | -------------------------------------------------------------------------------- /Vision/segmentation/FaceSeg/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oneflow-Inc/models/fc7cbf8da9b2ee21fa0e9613dd0668c3b45dad4d/Vision/segmentation/FaceSeg/utils/__init__.py -------------------------------------------------------------------------------- /Vision/segmentation/U-Net/log.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | 5 | class Logger: 6 | def __init__(self, filename="log.txt"): 7 | self.terminal = sys.stdout 8 | self.log = open(filename, "w") 9 | 10 | def write(self, message): 11 | self.log.write(message) 12 | 13 | def flush(self): 14 | pass 15 | 16 | def close(self): 17 | self.log.close() 18 | -------------------------------------------------------------------------------- /Vision/segmentation/U-Net/plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | 4 | def plot_picture(filename): 5 | with open(filename, "r") as f: 6 | train_loss = f.readlines() 7 | train_loss = list(map(lambda x: float(x.strip()), train_loss)) 8 | x = range(len(train_loss)) 9 | y = train_loss 10 | plt.plot( 11 | x, 12 | y, 13 | label="train loss", 14 | linewidth=2, 15 | color="r", 16 | marker="o", 17 | markerfacecolor="r", 18 | markersize=5, 19 | ) 20 | plt.xlabel("epoch") 21 | plt.ylabel("loss value") 22 | plt.legend() 23 | plt.show() 24 | -------------------------------------------------------------------------------- /Vision/segmentation/U-Net/requirements.txt: -------------------------------------------------------------------------------- 1 | matplotlib==3.3.2 2 | numpy==1.19.2 3 | oneflow==0.6.0.dev20211115+cpu 4 | opencv_python==4.2.0.34 5 | -------------------------------------------------------------------------------- /Vision/segmentation/U-Net/test.sh: -------------------------------------------------------------------------------- 1 | set -aux 2 | 3 | OFRECORD_PATH="predict_image" 4 | if [ ! -d "$OFRECORD_PATH" ]; then 5 | wget https://oneflow-static.oss-cn-beijing.aliyuncs.com/Dataset/Seg/ISBI_Challenge_cell_segmentation/predict_image.tar.gz 6 | tar xvf predict_image.tar.gz 7 | fi 8 | 9 | 10 | CHECKPOINT='./checkpoints' 11 | TEST_DATA_PATH='test_image/' 12 | SAVE_RES_PATH="./predict_image/test.png" 13 | 14 | 15 | python3 predict_unet_test.py \ 16 | --checkpoint $CHECKPOINT \ 17 | --Test_Data_path $TEST_DATA_PATH \ 18 | --save_res_path $SAVE_RES_PATH \ 19 | -------------------------------------------------------------------------------- /Vision/style_transform/fast_neural_style/requirements.txt: -------------------------------------------------------------------------------- 1 | opencv_python 2 | numpy 3 | -------------------------------------------------------------------------------- /dev-requirements.txt: -------------------------------------------------------------------------------- 1 | black==19.10b0 ; python_version >= "3.6" 2 | -------------------------------------------------------------------------------- /ops/__init__.py: -------------------------------------------------------------------------------- 1 | from .roi_align import RoIAlign 2 | from .nms import nms 3 | 4 | 5 | def lib_path(): 6 | import os 7 | import glob 8 | 9 | dir_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 10 | libs = glob.glob(os.path.join(dir_path, "*.so")) 11 | assert len(libs) > 0, f"no .so found in {dir_path}" 12 | return libs[0] 13 | -------------------------------------------------------------------------------- /ops/csrc/nms.cpp: -------------------------------------------------------------------------------- 1 | #include "oneflow/core/framework/framework.h" 2 | 3 | namespace oneflow { 4 | 5 | REGISTER_USER_OP("nms") 6 | .Input("in") 7 | .Output("out") 8 | .Attr("iou_threshold") 9 | .Attr("keep_n") 10 | .SetTensorDescInferFn([](user_op::InferContext* ctx) -> Maybe { 11 | Shape* in_shape = ctx->Shape4ArgNameAndIndex("in", 0); 12 | Shape* out_shape = ctx->Shape4ArgNameAndIndex("out", 0); 13 | *out_shape = Shape({in_shape->At(0)}); 14 | return Maybe::Ok(); 15 | }) 16 | .SetDataTypeInferFn([](user_op::InferContext* ctx) -> Maybe { 17 | *ctx->Dtype4ArgNameAndIndex("out", 0) = DataType::kInt8; 18 | return Maybe::Ok(); 19 | }) 20 | .SetGetSbpFn(user_op::GetSbpFnUtil::DefaultBroadcastToBroadcast); 21 | ; 22 | 23 | } // namespace oneflow 24 | -------------------------------------------------------------------------------- /ops/csrc/roi_align.h: -------------------------------------------------------------------------------- 1 | #include "oneflow/core/framework/op_expr.h" 2 | 3 | namespace oneflow { 4 | namespace op_expr_helper { 5 | 6 | Maybe RoIAlignGradOp(const int32_t& pooled_h, const int32_t& pooled_w, 7 | const float& spatial_scale, const int32_t& sampling_ratio, 8 | const bool& aligned); 9 | Maybe RoIAlignGradOp(const int32_t& pooled_h, const int32_t& pooled_w, 10 | const float& spatial_scale, const int32_t& sampling_ratio, 11 | const bool& aligned, const std::string& name); 12 | 13 | } // namespace op_expr_helper 14 | } // namespace oneflow 15 | -------------------------------------------------------------------------------- /ops/nms.py: -------------------------------------------------------------------------------- 1 | import oneflow as flow 2 | import oneflow as flow_exp 3 | from oneflow import Tensor 4 | 5 | 6 | def nms(boxes: Tensor, scores: Tensor, iou_threshold: float) -> Tensor: 7 | scores_inds = flow_exp.argsort(scores, dim=0, descending=True) 8 | boxes = flow._C.gather(boxes, scores_inds, axis=0) 9 | _nms_op = ( 10 | flow_exp.builtin_op("nms") 11 | .Input("in") 12 | .Output("out") 13 | .Attr("iou_threshold", iou_threshold) 14 | .Attr("keep_n", -1) 15 | .Build() 16 | ) 17 | keep = _nms_op(boxes)[0] 18 | index = flow_exp.squeeze(flow_exp.argwhere(keep), dim=[1]) 19 | return flow._C.gather(scores_inds, index, axis=0) 20 | --------------------------------------------------------------------------------