if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--train_path', type=str, default='data/cifar10_train.zip', help='Path to train dataset') parser.add_argument('--val_path', type=str, default='data/cifar10_val.zip', help='Path to validation dataset') parser.add_argument('--test_path', type=str, default='data/cifar10_test.zip', help='Path to test dataset') parser.add_argument( '--query_path', type=str, default='examples/data/image_classification/cifar10_test_1.png', help='Path(s) to query image(s), delimited by commas') (args, _) = parser.parse_known_args() queries = utils.dataset.load_images(args.query_path.split(',')).tolist() test_model_class(model_file_path=__file__, model_class='TfVgg16', task='IMAGE_CLASSIFICATION', dependencies={ModelDependency.TENSORFLOW: '1.12.0'}, train_dataset_path=args.train_path, val_dataset_path=args.val_path, test_dataset_path=args.test_path, queries=queries)
max_iterations =self._knobs.get('max_iterations') clf = CRF( algorithm='lbfgs', c1=c1, c2=c2, max_iterations=max_iterations, all_possible_transitions=True ) return clf if __name__ == '__main__': test_model_class( model_file_path=__file__, model_class='CRFClf', task='POS_TAGGING', dependencies={ ModelDependency.SCIKIT_LEARN: '0.20.0', ModelDependency.NLTK: '3.4.5', ModelDependency.SKLEARN_CRFSUITE: '0.3.6' }, train_dataset_path='data/ptb_train.txt', val_dataset_path='data/ptb_test.txt', queries=[ ['Ms.', 'Haag', 'plays', 'Elianti', '18', '.'], ['The', 'luxury', 'auto', 'maker', 'last', 'year', 'sold', '1,214', 'cars', 'in', 'the', 'U.S.'] ] )
if __name__ == '__main__': curpath = os.path.join(os.environ['HOME'], 'singa_auto') os.environ.setdefault('WORKDIR_PATH', curpath) os.environ.setdefault('PARAMS_DIR_PATH', os.path.join(curpath, 'params')) train_set_url = os.path.join(curpath, 'data', 'application_train_index.csv') valid_set_url = train_set_url test_set_url = os.path.join(curpath, 'data', 'application_test_index.csv') test_queries = pd.read_csv(test_set_url, index_col=0).iloc[:5] test_queries = json.loads(test_queries.to_json(orient='records')) test_model_class( model_file_path=__file__, model_class='LightGBM', task=None, dependencies={ ModelDependency.TENSORFLOW: '1.12.0', 'lightgbm': '2.3.0', }, train_dataset_path=train_set_url, val_dataset_path=valid_set_url, train_args={ 'target': 'TARGET', 'exclude': ['SK_ID_CURR'], }, queries=test_queries, )
test_model_class(model_file_path=__file__, model_class='XgbReg', task='TABULAR_REGRESSION', dependencies={ModelDependency.XGBOOST: '0.90'}, train_dataset_path='data/bodyfat_train.csv', val_dataset_path='data/bodyfat_val.csv', train_args={ 'features': [ 'density', 'age', 'weight', 'height', 'neck', 'chest', 'abdomen', 'hip', 'thigh', 'knee', 'ankle', 'biceps', 'forearm', 'wrist' ], 'target': 'bodyfat' }, queries=[{ 'density': 1.0207, 'age': 65, 'weight': 224.5, 'height': 68.25, 'neck': 38.8, 'chest': 119.6, 'abdomen': 118.0, 'hip': 114.3, 'thigh': 61.3, 'knee': 42.1, 'ankle': 23.4, 'biceps': 34.9, 'forearm': 30.1, 'wrist': 19.4 }])
) return clf if __name__ == '__main__': test_model_class(model_file_path=__file__, model_class='SVCClf', task='TABULAR_CLASSIFICATION', dependencies={ModelDependency.SCIKIT_LEARN: '0.20.0'}, train_dataset_path='data/diabetes_train.csv', val_dataset_path='data/diabetes_val.csv', train_args={ 'features': [ 'Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness', 'Insulin', 'DiabetesPedigreeFunction', 'BMI', 'Age' ], 'target': 'Outcome' }, queries={ 'Pregnancies': 3, 'Glucose': 130, 'BloodPressure': 92, 'SkinThickness': 30, 'Insulin': 90, 'DiabetesPedigreeFunction': 1, 'BMI': 30.4, 'Age': 40 })
-0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242], [-0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242, -0.4242]]]]) ] # can not run dist training using this scripts, as each process will be in the container at runtime test_model_class(model_file_path=__file__, model_class='DistMinist', task='IMAGE_CLASSIFICATION', dependencies={"torch": '1.0.1', "torchvision": '0.2.2'}, train_dataset_path=args.train_path, val_dataset_path=args.val_path, test_dataset_path=args.test_path, queries=queries, train_args={"use_dist": False }, ) """ Test the model out of singa-auto platform python -c "import torch;print(torch.cuda.is_available())" """ # a = DistMinist() # model_file = "20.model" # with open(model_file, 'rb') as f: # content = f.read()
sc = StandardScaler() return sc.fit_transform(X) def _build_classifier(self, n_neighbors, metric, p): clf = KNeighborsClassifier(n_neighbors=n_neighbors, metric=metric, p=p) return clf if __name__ == '__main__': test_model_class(model_file_path=__file__, model_class='KNNClf', task='TABULAR_CLASSIFICATION', dependencies={ModelDependency.SCIKIT_LEARN: '0.20.0'}, train_dataset_path='data/heart_train.csv', val_dataset_path='data/heart_test.csv', queries=[{ 'age': 50, 'Sex': '0', 'cp': 3, 'trestbps': 130, 'chol': 220, 'fbs': 1, 'restecg': 0, 'thalach': 170, 'exang': 1, 'oldpeak': 1.7, 'slope': 2, 'ca': 0, 'thal': 3 }])
X = PCA().fit_transform(data) return X def _build_classifier(self, penalty, tol, C, fit_intercept, solver): clf = LogisticRegression( penalty=penalty, tol=tol, C=C, fit_intercept=fit_intercept, solver=solver, ) return clf if __name__ == '__main__': test_model_class(model_file_path=__file__, model_class='LogisticRegClf', task='TABULAR_CLASSIFICATION', dependencies={ModelDependency.SCIKIT_LEARN: '0.20.0'}, train_dataset_path='data/diabetes_train.csv', val_dataset_path='data/diabetes_val.csv', queries=[{ 'Pregnancies': 3, 'Glucose': '130', 'BloodPressure': 92, 'SkinThickness': 30, 'Insulin': 90, 'BMI': 30.4, 'Age': 40 }])
curpath = os.path.join(os.environ['HOME'], 'singa_auto') os.environ.setdefault('WORKDIR_PATH', curpath) os.environ.setdefault('PARAMS_DIR_PATH', os.path.join(curpath, 'params')) train_set_url = os.path.join(curpath, 'data', 'application_train_index.csv') valid_set_url = train_set_url test_set_url = os.path.join(curpath, 'data', 'application_test_index.csv') test_queries = pd.read_csv(test_set_url, index_col=0).iloc[:5] test_queries = json.loads(test_queries.to_json(orient='records')) test_model_class( model_file_path=__file__, model_class='DNNTorch', task='TABULAR_CLASSIFICATION', dependencies={ ModelDependency.TORCH: '1.3.1', ModelDependency.SCIKIT_LEARN: '0.21.3', # 'fastai':'0.7.0' 'sklearn-pandas': '1.8.0', }, train_dataset_path=train_set_url, val_dataset_path=valid_set_url, train_args={ 'target': 'TARGET', 'exclude': ['SK_ID_CURR'], }, queries=test_queries, )
if __name__ == '__main__': test_model_class(model_file_path=__file__, model_class='GaussianClf', task='TABULAR_CLASSIFICATION', dependencies={ModelDependency.SCIKIT_LEARN: '0.20.0'}, train_dataset_path='data/heart_train.csv', val_dataset_path='data/heart_val.csv', train_args={ 'features': [ 'age', 'sex', 'cp', 'trestbps', 'chol', 'fbs', 'restecg', 'thalach', 'exang', 'oldpeak', 'slope', 'ca', 'thal'], 'target': 'target' }, queries={ 'age': 48, 'sex': 1, 'cp': 2, 'trestbps': 130, 'chol': 225, 'fbs': 1, 'restecg': 1, 'thalach': 172, 'exang': 1, 'oldpeak': 1.7, 'slope': 2, 'ca': 0, 'thal': 3 })
if __name__ == '__main__': test_model_class(model_file_path=__file__, model_class='RidgeReg', task='TABULAR_REGRESSION', dependencies={ModelDependency.SCIKIT_LEARN: '0.20.0'}, train_dataset_path='data/boston_train.csv', val_dataset_path='data/boston_val.csv', train_args={ 'features': [ 'CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'RAD', 'TAX', 'PTRATIO', 'B', 'LSTAT' ], 'target': 'MEDV' }, queries=[{ 'CRIM': 60.1, 'ZN': 0.001, 'INDUS': 18.1, 'CHAS': 0, 'NOX': 597, 'RM': 6.23, 'AGE': 50.0, 'DIS': 1.222, 'RAD': 23, 'TAX': 700, 'PTRATIO': 20.1, 'B': 1.54, 'LSTAT': 11.09 }])
subsample=subsample, colsample_bytree=colsample_bytree) else: clf = xgb.XGBClassifier(n_estimators=n_estimators, min_child_weight=min_child_weight, max_depth=max_depth, gamma=gamma, subsample=subsample, colsample_bytree=colsample_bytree, objective='multi:softmax', num_class=num_class) return clf if __name__ == '__main__': test_model_class(model_file_path=__file__, model_class='XgbClf', task='TABULAR_CLASSIFICATION', dependencies={ModelDependency.XGBOOST: '0.90'}, train_dataset_path='data/titanic_train.csv', val_dataset_path='data/titanic_val.csv', train_args={ 'features': ['Pclass', 'Sex', 'Age'], 'target': 'Survived' }, queries=[{ 'Pclass': 1, 'Sex': 'female', 'Age': 2.0 }])
parser = argparse.ArgumentParser() parser.add_argument('--train_path', type=str, default='data/cifar10_train.zip', help='Path to train dataset') parser.add_argument('--val_path', type=str, default='data/cifar10_val.zip', help='Path to validation dataset') parser.add_argument('--test_path', type=str, default='data/cifar10_test.zip', help='Path to test dataset') parser.add_argument( '--query_path', type=str, default='examples/data/image_classification/0-3096.png', help='Path(s) to query image(s), delimited by commas') (args, _) = parser.parse_known_args() queries = utils.dataset.load_images(args.query_path.split(',')) test_model_class(model_file_path=__file__, model_class='OnnxResNet18', task='IMAGE_CLASSIFICATION', dependencies={ModelDependency.SINGA: '3.0.0', ModelDependency.ONNX: '1.15.0'}, train_dataset_path=args.train_path, val_dataset_path=args.val_path, test_dataset_path=args.test_path, queries=queries)
if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--train_path', type=str, default='data/fashion_mnist_train.zip', help='Path to train dataset') parser.add_argument('--val_path', type=str, default='data/fashion_mnist_val.zip', help='Path to validation dataset') parser.add_argument('--test_path', type=str, default='data/fashion_mnist_test.zip', help='Path to test dataset') parser.add_argument( '--query_path', type=str, default='examples/data/image_classification/fashion_mnist_test_1.png', help='Path(s) to query image(s), delimited by commas') (args, _) = parser.parse_known_args() queries = utils.dataset.load_images(args.query_path.split(',')).tolist() test_model_class(model_file_path=__file__, model_class='SkDt', task='IMAGE_CLASSIFICATION', dependencies={ModelDependency.SCIKIT_LEARN: '0.20.0'}, train_dataset_path=args.train_path, val_dataset_path=args.val_path, test_dataset_path=args.test_path, queries=queries)
words_embed_tsr = self._word_embed(words_tsr.view(-1)).view(N, W, Ew) # Apply dropout to word rep (N x W x Ew) words_rep_tsr = self._word_dropout(words_embed_tsr) # Apply bidirectional LSTM to word rep sequence (N x W x 2h) (words_hidden_rep_tsr, _) = self._word_lstm(words_rep_tsr) words_hidden_rep_tsr = words_hidden_rep_tsr.contiguous() # Apply linear + softmax operation for sentence rep for all sentences (N x W x t) word_probs_tsr = F.softmax(self._word_lin(words_hidden_rep_tsr.view(N * W, self._h * 2)), dim=1).view(N, W, t) return word_probs_tsr if __name__ == '__main__': test_model_class( model_file_path=__file__, model_class='PyBiLstm', task='POS_TAGGING', dependencies={ ModelDependency.TORCH: '0.4.1' }, train_dataset_path='data/ptb_train.zip', val_dataset_path='data/ptb_val.zip', queries=[ ['Ms.', 'Haag', 'plays', 'Elianti', '18', '.'], ['The', 'luxury', 'auto', 'maker', 'last', 'year', 'sold', '1,214', 'cars', 'in', 'the', 'U.S.'] ] )
for col in cat_cols: df_temp[col] = df[col].map(self._encoding_dict[col]) df = df_temp return df def _build_classifier(self, n_estimators, max_depth, oob_score, max_features): clf = RandomForestClassifier(n_estimators=n_estimators, max_depth=max_depth, oob_score=oob_score, max_features=max_features) return clf if __name__ == '__main__': test_model_class(model_file_path=__file__, model_class='RandomForestClf', task='TABULAR_CLASSIFICATION', dependencies={ModelDependency.SCIKIT_LEARN: '0.20.0'}, train_dataset_path='data/titanic_train.csv', val_dataset_path='data/titanic_test.csv', train_args={ 'features': ['Pclass', 'Sex', 'Age'], 'target': 'Survived' }, queries=[{ 'Pclass': 1, 'Sex': 'female', 'Age': 16.0 }])
default='data/val.zip', help='Path to validation dataset') parser.add_argument('--test_path', type=str, default='data/test.zip', help='Path to test dataset') print(os.getcwd()) parser.add_argument( '--query_path', type=str, default= # 'examples/data/image_classification/xray_1.jpeg,examples/data/image_classification/IM-0103-0001.jpeg,examples/data/image_classification/NORMAL2-IM-0023-0001.jpeg', # 'examples/data/image_classification/IM-0001-0001.jpeg,examples/data/image_classification/IM-0003-0001.jpeg,examples/data/image_classification/IM-0005-0001.jpeg', 'examples/data/image_classification/cifar10_test_1.png,examples/data/image_classification/cifar10_test_2.png,examples/data/image_classification/fashion_mnist_test_1.png,examples/data/image_classification/fashion_mnist_test_2.png', help='Path(s) to query image(s), delimited by commas') (args, _) = parser.parse_known_args() queries = utils.dataset.load_images(args.query_path.split(',')).tolist() test_model_class(model_file_path=__file__, model_class='PyPandaVgg', task='IMAGE_CLASSIFICATION', dependencies={ ModelDependency.TORCH: '1.0.1', ModelDependency.TORCHVISION: '0.2.2' }, train_dataset_path=args.train_path, val_dataset_path=args.val_path, test_dataset_path=args.test_path, queries=queries)
backpointer = i # Traverse backpointers to get most probable tags cur = backpointer w = len(tokens) - 1 sent_tags = [] while cur is not None: sent_tags.append(cur) cur = backpointers[w][cur] w -= 1 sent_tags.reverse() sents_tags.append(sent_tags) return sents_tags if __name__ == '__main__': test_model_class( model_file_path=__file__, model_class='BigramHmm', task='POS_TAGGING', dependencies={}, train_dataset_path='/Users/nailixing/Downloads/data/ptb_train.zip', val_dataset_path='/Users/nailixing/Downloads/data/ptb_val.zip', queries=[['Ms.', 'Haag', 'plays', 'Elianti', '18', '.'], [ 'The', 'luxury', 'auto', 'maker', 'last', 'year', 'sold', '1,214', 'cars', 'in', 'the', 'U.S.' ]])
if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--train_path', type=str, default='data/fashion_mnist_train.zip', help='Path to train dataset') parser.add_argument('--val_path', type=str, default='data/fashion_mnist_val.zip', help='Path to validation dataset') parser.add_argument('--test_path', type=str, default='data/fashion_mnist_test.zip', help='Path to test dataset') parser.add_argument( '--query_path', type=str, default='examples/data/image_classification/fashion_mnist_test_1.png', help='Path(s) to query image(s), delimited by commas') (args, _) = parser.parse_known_args() queries = utils.dataset.load_images(args.query_path.split(',')).tolist() test_model_class(model_file_path=__file__, model_class='LeNet5', task='IMAGE_CLASSIFICATION', dependencies={ModelDependency.KERAS: '2.2.4'}, train_dataset_path=args.train_path, val_dataset_path=args.val_path, test_dataset_path=args.test_path, queries=queries)
(args, _) = parser.parse_known_args() # queries = open(args.queries_file_path,'r') # queries = queries.read().replace("'", "\"") # queries = json.loads(queries) # queries = [queries] queries = [{ 'questions': [ 'How long individuals are contagious?', # 'What is the range of the incubation period in humans?', ] }] test_model_class( model_file_path=__file__, model_class='QuestionAnswering', task='question_answering_covid19', # higher version of sentence-transformers and transformers are recommended to avoid 'ndim' and padding issue dependencies={ ModelDependency.TORCH: '1.0.1', "torchvision": "0.2.2", 'semanticscholar': '0.1.4', 'sentence_transformers': '0.3.2', "transformers": '3.0.2', "tqdm": "4.27", }, train_dataset_path='', val_dataset_path='', fine_tune_dataset_path=args.fine_tune_dataset_path, queries=queries)
print(args.query_path.split(',')) queries = utils.dataset.load_images(args.query_path.split(',')) test_model_class( model_file_path=__file__, model_class='SaMaskRcnn', task='IMAGE_DETECTION', dependencies={ "torch": "1.4.0+cu100", "torchvision": "0.5.0+cu100", "opencv-python": "4.2.0.34", "pycocotools": "2.0.1" }, train_dataset_path=args.train_path, val_dataset_path=args.val_path, annotation_dataset_path=args.annotation_dataset_path, test_dataset_path=None, train_args={ "num_classes": 3, "num_epoch": 1, "dataset_name": "coco2017", "filter_classes": ["car", 'cat'], # "dataset_name": "pennfudan", "batch_size": 2 }, queries=queries) """ Test the model out of singa-auto platform python -c "import torch;print(torch.cuda.is_available())" """