def main(api_endpoint):
    email = input('Enter email: ')
    password = getpass.getpass()
    source_project_id = input(
        'Enter project IDs (separate them by "," if you want to provide several): '
    )

    kauth = KiliAuth(email=email, password=password, api_endpoint=api_endpoint)
    playground = Playground(kauth)

    df = pd.DataFrame(columns=['Project', 'Date', 'Email'])
    for project_id in source_project_id.split(','):
        project = playground.projects(project_id=project_id)[0]
        assets = playground.assets(project_id=project_id)
        title = project['title']
        for asset in assets:
            for label in asset['labels']:
                created_at = label['createdAt'][:10]
                author_email = label['author']['email']
                df = df.append(
                    {
                        'Project': title,
                        'Date': created_at,
                        'Email': author_email
                    },
                    ignore_index=True)
    df_grouped = df.groupby(['Project', 'Date', 'Email']).size()
    time = datetime.now().strftime('%Y%m%d%H%M')
    df_grouped.to_excel(f'labeler-stats-{time}.xlsx')
Exemplo n.º 2
0
def main():
    logging.info("Reading & parsing arguments...")
    args = read_arguments()

    logging.info("Reading predictions files")
    with open(args.annotations_path, 'r') as f:
        configuration = yaml.safe_load(f)

    predictions = configuration['predictions']

    logging.info("Connecting to Kili")
    kauth = KiliAuth(email=args.email,
                     password=args.password,
                     api_endpoint=args.api_endpoint)
    playground = Playground(kauth)

    logging.info("Getting predictions")
    external_id_array = [
        get(prediction, 'externalId') for prediction in predictions
    ]
    json_response_array = [
        json.loads(get(prediction, 'response')) for prediction in predictions
    ]

    logging.info("Uploading to Kili")
    playground.create_predictions(project_id=args.project_id,
                                  external_id_array=external_id_array,
                                  json_response_array=json_response_array)
Exemplo n.º 3
0
class ActiveLearner:
    def __init__(self, email, password, api_endpoint, project_id):
        kauth = KiliAuth(email, password, api_endpoint=api_endpoint)
        self.playground = Playground(kauth)
        self.project_id = project_id

    def get_assets_to_evaluate(self):
        assets = self.playground.assets(project_id=self.project_id)
        assets_to_evaluate = []
        for asset in assets:
            if len(asset['labels']) == 0:
                assets_to_evaluate.append(asset)

        return assets_to_evaluate

    def prioritize_assets(self, assets, scorer, *args, **kwargs):
        assets_score = [scorer(asset, *args, **kwargs) for asset in assets]
        ranked_assets_with_score = sorted(list(zip(assets, assets_score)),
                                          key=lambda x: x[1],
                                          reverse=True)
        ranked_assets = [
            asset_with_score[0]
            for asset_with_score in ranked_assets_with_score
        ]
        return ranked_assets

    def update_assets_priority(self, assets):
        for i, asset in enumerate(tqdm(assets)):
            asset_id = asset['id']
            self.playground.update_properties_in_asset(asset_id=asset_id,
                                                       priority=i)
        return True
def main(api_endpoint):
    email = input('Enter email: ')
    password = getpass.getpass()
    project_id = input('Enter project id: ')

    with open('./conf/new_assets.yml', 'r') as f:
        configuration = yaml.safe_load(f)

    assets = configuration['assets']

    kauth = KiliAuth(email, password, api_endpoint)
    playground = Playground(kauth)

    project = playground.get_project(project_id=project_id)
    roles = get(project, 'roles')

    for asset in tqdm(assets):
        external_id = get(asset, 'externalId')
        to_be_labeled_by = [
            get(user, 'email') for user in get(asset, 'toBeLabeledBy')
        ]
        asset = get_asset_by_external_id(playground, project_id, external_id)
        asset_id = get(asset, 'id')
        playground.update_properties_in_asset(
            asset_id=asset_id, to_be_labeled_by=to_be_labeled_by)
    def __init__(self, email, password, api_endpoint, project_id, minimum_number_of_assets_to_launch_training=100):
        kauth = KiliAuth(email, password, api_endpoint=api_endpoint)

        self.playground = Playground(kauth)
        self.project_id = project_id
        self.current_training_number = 0
        self.last_training_number = -1
        self.assets_seen_in_training = []
        self.minimum_number_of_assets_to_launch_training = minimum_number_of_assets_to_launch_training
Exemplo n.º 6
0
def main(api_endpoint):
    api_key = input('Enter API KEY: ')
    project_id = input('Enter project id: ')
    title = input(
        'Enter a new title (leave blank and press [Enter] to leave title as is): ').strip()
    description = input(
        'Enter a new description (leave blank and press [Enter] to leave description as is): ').strip()

    kauth = KiliAuth(api_key=api_key, api_endpoint=api_endpoint)
    playground = Playground(kauth)
    playground.update_properties_in_project(
        project_id=project_id, title=title, description=description)
Exemplo n.º 7
0
def main(api_endpoint):
    api_key = input('Enter API KEY: ')
    project_id = input('Enter project id: ')
    instructions = input(
        'Enter link to instructions (leave blank and press [Enter] to disable instructions): '
    ).strip()

    if not instructions.startswith('http') and not instructions == '':
        raise Exception(
            'The link to instructions should be an URL beginning in http:// or https://'
        )

    kauth = KiliAuth(api_key=api_key, api_endpoint=api_endpoint)
    playground = Playground(kauth)
    playground.update_properties_in_project(project_id=project_id,
                                            instructions=instructions)
Exemplo n.º 8
0
    def __init__(self,
                 api_key,
                 api_endpoint,
                 project_id,
                 number_of_inferences,
                 minimum_number_of_assets_to_launch_training=100):
        kauth = KiliAuth(api_key=api_key, api_endpoint=api_endpoint)

        self.playground = Playground(kauth)
        self.project_id = project_id
        self.current_inference_number = 0
        self.current_training_number = 0
        self.last_training_number = -1
        self.assets_seen_in_training = []
        self.minimum_number_of_assets_to_launch_training = minimum_number_of_assets_to_launch_training
        self.number_of_inferences = number_of_inferences
Exemplo n.º 9
0
def main(api_endpoint):
    email = input('Enter email: ')
    password = getpass.getpass()
    project_id = input('Enter project id: ')
    title = input(
        'Enter a new title (leave blank and press [Enter] to leave title as is): '
    ).strip()
    description = input(
        'Enter a new description (leave blank and press [Enter] to leave description as is): '
    ).strip()

    kauth = KiliAuth(email, password, api_endpoint=api_endpoint)
    playground = Playground(kauth)
    playground.update_properties_in_project(project_id=project_id,
                                            title=title,
                                            description=description)
def main(api_endpoint):
    email = input('Enter Email: ')
    password = getpass.getpass('Enter password for user {}:'.format(email))
    kauth = KiliAuth(email, password, api_endpoint=api_endpoint)
    playground = Playground(kauth)
    project_id = input('Enter project id: ')

    # Check and load new predictions
    STOP_CONDITION = True
    while STOP_CONDITION:
        tools = playground.get_tools(project_id=project_id)
        assert len(tools) == 1
        categories = list(
            json.loads(tools[0]['jsonSettings'])['categories'].keys())

        print('Export assets and labels...')
        assets = playground.export_assets(project_id=project_id)
        print('Done.\n')
        X, y, X_to_be_predicted, ids_X_to_be_predicted = extract_train_for_autoML(
            assets, categories)

        if len(X) > 5:
            print('Online Learning is on its way...')
            predictions = automl_train_and_predict(X, y, X_to_be_predicted)
            # Insert pre-annotations
            for i, prediction in enumerate(tqdm(predictions)):
                json_response = {
                    'categories': [{
                        'name': categories[prediction],
                        'confidence': 100
                    }]
                }
                id = ids_X_to_be_predicted[i]
                playground.create_prediction(asset_id=id,
                                             json_response=json_response)
            print('Done.\n')
        time.sleep(SECONDS_BETWEEN_TRAININGS)
Exemplo n.º 11
0
class TransferLearning:
    def __init__(self,
                 api_key,
                 api_endpoint,
                 project_id,
                 number_of_inferences,
                 minimum_number_of_assets_to_launch_training=100):
        kauth = KiliAuth(api_key=api_key, api_endpoint=api_endpoint)

        self.playground = Playground(kauth)
        self.project_id = project_id
        self.current_inference_number = 0
        self.current_training_number = 0
        self.last_training_number = -1
        self.assets_seen_in_training = []
        self.minimum_number_of_assets_to_launch_training = minimum_number_of_assets_to_launch_training
        self.number_of_inferences = number_of_inferences

    def _current_training_number(self):
        return self.current_training_number

    def get_assets_to_train(self):
        assets = self.playground.assets(project_id=self.project_id)
        assets_to_train = []
        for asset in assets:
            default_labels = get_labels_of_types(asset, ['DEFAULT'])
            review_labels = get_labels_of_types(asset, ['REVIEWED'])
            if len(review_labels) > 0:
                asset['labels'] = [review_labels[-1]]
                assets_to_train.append(asset)
            elif len(default_labels) == 1:
                asset['labels'] = [default_labels[-1]]
                assets_to_train.append(asset)
            elif len(review_labels) == 0 and len(default_labels) > 0:
                print(
                    f'Asset {asset["id"]} has several labels: it should be reviewed'
                )
            else:
                continue

        return assets_to_train

    def train(self, assets_to_train):
        print(
            f'Launch training for {len(assets_to_train)} assets: {[asset["id"] for asset in assets_to_train]}'
        )
        return

    def launch_train(self):
        time.sleep(SECONDS_TO_WAIT)
        assets_to_train = self.get_assets_to_train()
        if len(self.assets_seen_in_training) == 0:
            filtered_assets_to_train = assets_to_train
        else:
            filtered_assets_to_train = [
                asset for asset in assets_to_train if all([
                    asset['id'] not in training
                    for training in self.assets_seen_in_training
                ])
            ]
        if len(filtered_assets_to_train
               ) >= self.minimum_number_of_assets_to_launch_training:
            self.train(filtered_assets_to_train)
            self.current_training_number += 1
            self.assets_seen_in_training.append(
                [asset['id'] for asset in filtered_assets_to_train])

    def get_assets_to_predict(self):
        assets = self.playground.assets(project_id=self.project_id)
        assets_to_predict = []
        for asset in assets:
            labels = get_labels_of_types(asset, ['DEFAULT', 'REVIEWED'])

            if len(labels) == 0:
                assets_to_predict.append(asset)

        return assets_to_predict

    def predict(self, assets_to_predict):
        print(
            f'Launch inference for {len(assets_to_predict)} assets: {[asset["id"] for asset in assets_to_predict]}'
        )
        return

    def launch_predict(self):
        time.sleep(SECONDS_TO_WAIT)
        if self.current_training_number == self.last_training_number:
            print('Inference will not be launched for now...')
            return
        assets_to_predict = self.get_assets_to_predict()
        if len(assets_to_predict) > 0:
            current_training_number = self.current_training_number
            self.predict(assets_to_predict)
            self.last_training_number = current_training_number
            self.current_inference_number += 1

    def launch_tensorboard(self):
        print('Starting Tensorboard...')
        subprocess.Popen(['tensorboard', '--logdir=runs'])
        print('You can access Tensorboard at http://localhost:6006\n')

    def launch(self):
        self.launch_tensorboard()
        while self.current_inference_number < self.number_of_inferences:
            self.launch_train()
            self.launch_predict()
Exemplo n.º 12
0
    return dic[key]


email = input('Enter email: ')
password = getpass.getpass()
project_id = input('Enter project id: ')

with open('./conf/new_users.yml', 'r') as f:
    configuration = yaml.safe_load(f)

users = configuration['users']

DEFAULT_ORGANIZATION_ROLE = 'USER'

kauth = KiliAuth(email, password)
playground = Playground(kauth)

organization_id = playground.get_user(email=email)['organization']['id']

for user in tqdm(users):
    user_name = get(user, 'name')
    user_email = get(user, 'email')
    user_password = get(user, 'password')
    playground.create_user(name=user_name,
                           email=user_email,
                           password=user_password,
                           organization_id=organization_id,
                           organization_role=DEFAULT_ORGANIZATION_ROLE)
    user_role = get(user, 'role')
    playground.append_to_roles(project_id=project_id,
                               user_email=user_email,
Exemplo n.º 13
0

class Playground(
        kili.mutations.asset.MutationsAsset,
        kili.mutations.label.MutationsLabel,
        kili.mutations.organization.MutationsOrganization,
        kili.mutations.project.MutationsProject,
        kili.mutations.user.MutationsUser,
        kili.queries.asset.QueriesAsset,
        kili.queries.label.QueriesLabel,
        kili.queries.organization.QueriesOrganization,
        kili.queries.project.QueriesProject,
        kili.queries.project_user.QueriesProjectUser,
        kili.queries.user.QueriesUser,
        kili.subscriptions.label.SubscriptionsLabel):

    def __init__(self, auth=None):
        """Create an instance of KiliPlayground."""
        self.auth = auth
        super().__init__(auth)


if __name__ == '__main__':
    """ Example of usage """
    from kili.authentication import KiliAuth
    from kili.playground import Playground
    kauth = KiliAuth()
    playground = Playground(kauth)
    assets = playground.assets(project_id="first-project")
    print(assets)
Exemplo n.º 14
0
email = input('Enter email: ')
password = getpass.getpass()
project_id = input('Enter project id: ')

MAX_NUMBER_OF_ASSET = 50

path_gz = download_dataset()
path_dir = extract_dataset(path_gz)

only_files = [
    os.path.join(path, name) for path, subdirs, files in os.walk(path_dir)
    for name in files
]

kauth = KiliAuth(email=email, password=password)
playground = Playground(kauth)

for filepath in tqdm(only_files[:MAX_NUMBER_OF_ASSET]):
    with open(filepath, 'r') as f:
        content = f.read()
    external_id = filepath
    # Insert asset
    playground.append_to_dataset(project_id=project_id,
                                 content=escape_content(content),
                                 external_id=external_id)
    asset = playground.get_assets_(project_id=project_id,
                                   external_id_contains=[external_id])
    asset_id = asset[0]['id']

    # Prioritize assets
    playground.update_properties_in_asset(asset_id=asset_id, priority=1)
from kili.authentication import KiliAuth
from kili.playground import Playground

S3_ACCESS_KEY = os.getenv('S3_ACCESS_KEY')
S3_SECRET_KEY = os.getenv('S3_SECRET_KEY')
S3_ENDPOINT = os.getenv('S3_ENDPOINT')
S3_BUCKET = os.getenv('S3_BUCKET')

email = input('Enter email: ')
password = getpass.getpass()
project_id = input('Enter project id: ')

api_endpoint = 'https://cloud.kili-technology.com/api/label/graphql'
kauth = KiliAuth(email, password, api_endpoint)
playground = Playground(kauth)

s3_client = boto3.client('s3',
                         aws_access_key_id=S3_ACCESS_KEY,
                         aws_secret_access_key=S3_SECRET_KEY,
                         endpoint_url=S3_ENDPOINT,
                         verify=False)

with open('./conf/new_assets_with_s3.yml', 'r') as f:
    configuration = yaml.safe_load(f)
assets = configuration['assets']

for asset in tqdm(assets):
    # Uploads asset to S3 bucket
    path = get(asset, 'path')
    key = str(random.getrandbits(128))
Exemplo n.º 16
0
 def __init__(self, email, password, api_endpoint, project_id):
     kauth = KiliAuth(email, password, api_endpoint=api_endpoint)
     self.playground = Playground(kauth)
     self.project_id = project_id
Exemplo n.º 17
0
import os

from kili.authentication import KiliAuth
from kili.playground import Playground

email = os.getenv('KILI_EMAIL')
password = os.getenv('KILI_PASSWORD')
api_endpoint = 'https://cloud.kili-technology.com/api/label/graphql'

kauth = KiliAuth(email, password, api_endpoint)
playground = Playground(kauth)

title = 'Test'
description = 'Ceci est un projet test'
json_interface = {
    "filetype": "IMAGE",
    "jobs": {
        "JOB_0": {
            "mlTask": "OBJECT_DETECTION",
            "tools": ["rectangle"],
            "instruction": "Categories",
            "required": 1,
            "isChild": False,
            "content": {
                "categories": {
                    "OBJECT_A": {
                        "name": "Object A",
                        "children": ["JOB_1"]
                    },
                    "OBJECT_B": {
                        "name": "Object B",
Exemplo n.º 18
0
import getpass
import json

import yaml
from tqdm import tqdm

from kili.authentication import KiliAuth
from kili.playground import Playground

email = input('Enter email: ')
password = getpass.getpass()
project_id = input('Enter project id: ')

kauth = KiliAuth(email=email, password=password)
playground = Playground(kauth)

assets = playground.assets(project_id=project_id)
asset_ids = [asset['id'] for asset in assets]
playground.delete_many_from_dataset(asset_ids=asset_ids)
Exemplo n.º 19
0
import getpass
import json

import yaml
from tqdm import tqdm

from kili.authentication import KiliAuth
from kili.playground import Playground

email = input('Enter email: ')
password = getpass.getpass()
project_id = input('Enter project id: ')

kauth = KiliAuth(email=email, password=password)
playground = Playground(kauth)

assets = playground.get_assets(project_id=project_id)

for asset in tqdm(assets):
    playground.delete_from_dataset(asset_id=asset['id'])