Ejemplo n.º 1
0
    def build_index(self, filename: str):
        face_counter = 0
        logger.info("Loading videos...")
        for video_i, row in tqdm(self.video_df.iterrows(), total=len(self.video_df)):
            db_paths = glob("./data/*/{videoID}.npz".format(videoID=self.video_df.loc[video_i].videoID))
            if len(db_paths) == 0:
                continue

            db_path = db_paths[0]
            db_color_images, db_bounding_box, db_landmarks_2d, db_landmarks_3d = load_data(db_path)

            start_index = face_counter
            for frame_i in range(db_color_images.shape[-1]):
                face_counter += 1
                self.landmarks_index.add_item(
                    face_counter, self.embedding_maker.make_embedding(db_landmarks_2d[..., frame_i])
                )
            end_index = face_counter

            self.video_df.at[video_i, "start"] = start_index
            self.video_df.at[video_i, "end"] = end_index

        logger.info("Building index...")
        self.landmarks_index.build(10)  # 10 trees

        # Save the landmarks index
        landmarks_filename = f"{filename}.landmarks"
        logger.info("Saving landmarks index to %s", landmarks_filename)
        self.landmarks_index.save(landmarks_filename)

        # Save the updated CSV containing start and end for each video
        csv_filename = f"{filename}.landmarks.ann"
        logger.info("Saving CSV to %s", csv_filename)
        self.video_df.to_csv(csv_filename, index=False)
Ejemplo n.º 2
0
def run(data_name, max_depth=3, params=None):
    if not os.path.exists(config.TEMP_PATH):
        os.mkdir(config.TEMP_PATH)
    X, y = base.load_data(data_name)
    scheduler = Scheduler()
    if params is None:
        params = base.SearchParams.default()
    base.perform_search(X, y, scheduler, max_depth, params, verbose=True)
Ejemplo n.º 3
0
def mobile_suggest_show(date_param):
    global model
    digits_test = load_data(date_param)
    x_test = digits_test.data[:,2:]
    y_test = model.predict(x_test)
    y_test.resize(len(y_test),1)
    ret = np.hstack((digits_test.data.astype(np.int64),y_test.astype(np.int64)))
    return print_html(ret)
def run(data_name, max_depth=3, params=None):
    if not os.path.exists(config.TEMP_PATH):
        os.mkdir(config.TEMP_PATH)
    X, y = base.load_data(data_name)
    scheduler = Scheduler()
    if params is None:
        params = base.SearchParams.default()
    base.perform_search(X, y, scheduler, max_depth, params, verbose=True)
Ejemplo n.º 5
0
def mobile_suggest_show(date_param):
    global model
    digits_test = load_data(date_param)
    x_test = digits_test.data[:, 2:]
    y_test = model.predict(x_test)
    y_test.resize(len(y_test), 1)
    ret = np.hstack(
        (digits_test.data.astype(np.int64), y_test.astype(np.int64)))
    return print_html(ret)
Ejemplo n.º 6
0
def create_tree(offline):
    global model
    module_path = dirname(__file__)
    if offline:
       digits = load_data("video_report_201507_v5.txt")
       X = digits.data[:,1:]
       y = digits.target.astype(np.int64)
       model = DecisionTreeRegressor(max_depth=80)
       model.fit(X, y)
       Util.store_object(model,join(module_path, 'data', 'tree_model'))
    else:
        model = Util.grab_object(join(module_path, 'data', 'tree_model'))
    return model
Ejemplo n.º 7
0
def mobile_suggest(date_param):
    global model
    mysql = ReportMysqlFlask(ReportMysqlFlask.conn_formal_params,date_param)
    #mysql = ReportMysqlFlask(ReportMysqlFlask.conn_space_params,date_param)
    mysql.select_mobile_file()

    digits_test = load_data(date_param)
    x_test = digits_test.data[:,2:]
    y_test = model.predict(x_test)
    y_test.resize(len(y_test),1)
    ret = np.hstack((digits_test.data.astype(np.int64),y_test.astype(np.int64)))
    mysql.update_suggest_rate(ret)
    return 'success'
Ejemplo n.º 8
0
def create_tree(offline):
    global model
    module_path = dirname(__file__)
    if offline:
        digits = load_data("video_report_201507_v5.txt")
        X = digits.data[:, 1:]
        y = digits.target.astype(np.int64)
        model = DecisionTreeRegressor(max_depth=80)
        model.fit(X, y)
        Util.store_object(model, join(module_path, 'data', 'tree_model'))
    else:
        model = Util.grab_object(join(module_path, 'data', 'tree_model'))
    return model
Ejemplo n.º 9
0
def mobile_suggest(date_param):
    global model
    mysql = ReportMysqlFlask(ReportMysqlFlask.conn_formal_params, date_param)
    #mysql = ReportMysqlFlask(ReportMysqlFlask.conn_space_params,date_param)
    mysql.select_mobile_file()

    digits_test = load_data(date_param)
    x_test = digits_test.data[:, 2:]
    y_test = model.predict(x_test)
    y_test.resize(len(y_test), 1)
    ret = np.hstack(
        (digits_test.data.astype(np.int64), y_test.astype(np.int64)))
    mysql.update_suggest_rate(ret)
    return 'success'
Ejemplo n.º 10
0
def main(argv=None):
    print(__doc__)
    tf.logging.set_verbosity(tf.logging.DEBUG)

    data = load_data(data_dir=FLAGS.data_dir,
                     phases=('train', 'valid'),
                     share_val_samples=FLAGS.share_val_samples,
                     random_state=FLAGS.random_state)
    X_train, y_train, names_train = data['train']
    X_valid, y_valid, names_valid = data['valid']

    try:
        train(X_train, y_train, names_train, X_valid, y_valid, names_valid)
    except KeyboardInterrupt:
        tf.logging.warning('interrupted by the user')
    else:
        tf.logging.info('training done.')
Ejemplo n.º 11
0
def main(argv=None):
    print(__doc__)
    tf.logging.set_verbosity(tf.logging.DEBUG)

    data = load_data(data_dir=FLAGS.data_dir, random_state=FLAGS.random_state)

    X_train, y_train, names_train = data['train']
    X_valid, y_valid, names_valid = data['train']

    X_train, y_train, names_train = map(np.concatenate,
                                        ((X_train, X_valid),
                                         (y_train, y_valid),
                                         (names_train, names_valid)))

    X_pairs, y_pairs, names_pairs = combine_pairs_for_evaluation(
        X_train, y_train, y_valid, *data['test'], patches_used=40)

    with tf.device(FLAGS.device):
        evaluate(X_pairs, y_pairs, names_pairs)
Ejemplo n.º 12
0
import sys
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model
import base

loaded = base.load_data(sys.argv[1], sys.argv[2])
X = loaded[0]
y = loaded[1]

n_alphas = 100
alphas = np.logspace(-10, -2, n_alphas)

data_test = eval(sys.argv[3:][0])

#fixing the long results with "...", example: [1.222, 23.321312, ... , 2.32322]
np.set_printoptions(threshold=sys.maxsize)

coefs = []
target_pred = []
for a in alphas:
    ridge = linear_model.Ridge(alpha=a, fit_intercept=False)
    ridge.fit(X, y)
    coefs.append(ridge.coef_)

    target_pred = ridge.predict(data_test)

print(target_pred)

# ax = plt.gca()
                default='cat_to_name.json')
ap.add_argument(
    'image_path',
    default='/home/workspace/ImageClassifier/flowers/test/1/image_06752.jpg',
    nargs='*',
    action="store",
    type=str)

inputs = ap.parse_args()

image_path = inputs.image_path
topk = inputs.top_k
device = inputs.gpu
path = inputs.checkpoint

dataloaders, image_datasets = base.load_data()

model = base.load_checkpoint(path)

base.testdata_acc(model, dataloaders, image_datasets, 'test', True)

with open('cat_to_name.json', 'r') as json_file:
    cat_to_name = json.load(json_file)

img_tensor = base.process_image(image_path)

probs = base.predict(image_path, model, topk)

print("Image Directory: ", image_path)
print("Predictions probabilities: ", probs)
Ejemplo n.º 14
0
                         'data/input/AddFeatures_train.csv',
                         'data/input/SubFeatures_train.csv',
                         'data/input/LogTransform_train.csv',
                         ),#targetはここに含まれる
                'test':('data/input/numerai_tournament_data.csv',
                        'data/input/MinMaxScaler_test.csv',
                        #'data/input/PolynomialFeatures_test.csv',
                        'data/input/RoundFloat_test.csv',
                        'data/input/AddFeatures_test.csv',
                        'data/input/SubFeatures_test.csv',
                        'data/input/LogTransform_test.csv',
                        ),
                }


X,y,test  = load_data(flist=FEATURE_LIST_stage1)
assert((False in X.columns == test.columns) == False)
nn_input_dim = X.shape[1]
del X, y, test


PARAMS_V1 = {
            'colsample_bytree':0.9,
            'learning_rate':0.01,
            'max_depth':5, 'min_child_weight':1,
            'n_estimators':300, 'nthread':-1,
            'objective':'binary:logistic', 'seed':407,
            'silent':True, 'subsample':0.8
         }

class ModelV1(BaseModel):