Beispiel #1
0
def setup_env(project_path):
    """
    Sets up the env settings for the fabric tasks

    Checks your git repo and adds your remotes as
    aliases for those hosts. Letting you do -H web1,web2
    when you have web1 and web2 in your remotes

    Creates roles out of each section in the config file.
    Letting you do -R app-servers and that command will
    be passed to all app servers.

    Provides access to some variables that can be used through
    tasks.

        env.deploy_path: the local location of the deploy folder
        env.project_path: the local location of the root of your project
        env.git_repo_name: the remote name of the git repo.
        env.git_working_dir: the remote path where the code should be deployed

        env.config_object: The servers.ini file loaded by the config parser
        env.conf_filename: The path to the servers.ini file

        env.git_remotes: A mapping of git remote names to hosts
        env.git_reverse: The reverse of above
    """

    # Setup fabric env
    env.deploy_path = os.path.join(project_path, 'deploy')
    env.project_path = project_path
    env.git_repo_name = GIT_REPO_NAME
    env.git_working_dir = GIT_WORKING_DIR

    BASE = os.path.abspath(os.path.dirname(__file__))
    env.configs_dir = os.path.join(BASE, 'default-configs')

    # Read the config and store it in env
    config = CustomConfig()
    env.conf_filename = os.path.abspath(os.path.join(project_path, 'deploy', 'servers.ini'))
    config.read([ env.conf_filename ])
    env.config_object = config

    # Add sections to the roledefs
    for section in config.sections():
        if config.has_option(section, CustomConfig.CONNECTIONS):
            env.roledefs[section] = config.get_list(section, CustomConfig.CONNECTIONS)

    env.git_remotes = gather_remotes()
    env.git_reverse = dict([(v, k) for (k, v) in env.git_remotes.iteritems()])

    # Translate any known git names to hosts
    hosts = []
    for host in env.hosts:
        if host in env.git_remotes:
            host = env.git_remotes[host]
        hosts.append(host)
    env.hosts = hosts
Beispiel #2
0
import os
from config import CustomConfig

c = CustomConfig(path=os.path.abspath(os.path.dirname(__file__)))

# Returns Box Folder object if exists, None otherwise
def get_folder(client, root_folder, folder_name):
    items = client.folder(folder_id=c.root_folder_id).get_items(limit=10, offset=0)
    folders = {}
    for item in items:
        folders[item.get()['name']] = item.get()['id']
    if folder_name in folders:
        folder_id = folders[folder_name]
        return client.folder(folder_id=folder_id).get()
    else:
        return root_folder.create_subfolder(folder_name)
Beispiel #3
0
    "--val",
    type=bool,
    default=True,
    help="Whether to use photos from validation dataset or own picture")
parser.add_argument("--weights", type=str, required=True, help="Weights path")
parser.add_argument("--path",
                    type=str,
                    required=True,
                    help="Path to dataset or own picture")
args = parser.parse_args()

WEIGHTS_PATH = args.weights
MODEL_DIR = args.logs

print("[INFO] Initializing configs...")
config_ = CustomConfig()


class InferenceConfig(config_.__class__):
    GPU_COUNT = 1
    IMAGES_PER_GPU = 1
    NUM_CLASSES = 1 + 14  # Background + CLASSES
    DETECTION_MIN_CONFIDENCE = 0

    IMAGE_MAX_DIM = 256
    IMAGE_MIN_DIM = 256


config_ = InferenceConfig()
config_.display()
file_name = data['file']

# COMMAND REPLIES
add_text = 'Привет, это бот для проекта по распознаванию еды и определению количества калорий.\nОтправь фото и получи результат!'
about_text = 'Бот создан для МНСК-2021.\nАвторы: Оконешников Дмитрий, Паньков Максим.\nGithub: https://github.com/MagicWinnie/FoodRecognition'
help_text = """
            Доступные команды:
            /start - начало работы с ботом
            /help  - команды бота
            /about - информация о боте
            """

# MODEL


config = CustomConfig()


class InferenceConfig(config.__class__):
    GPU_COUNT = 1
    IMAGES_PER_GPU = 1
    NUM_CLASSES = 1 + 14
    DETECTION_MIN_CONFIDENCE = 0
    IMAGE_MAX_DIM = 256
    IMAGE_MIN_DIM = 256


config = InferenceConfig()

model = modellib.MaskRCNN(mode='inference',
                          config=config,
Beispiel #5
0
                    type=int,
                    default=20,
                    help="Number of epochs to learn")
args = parser.parse_args()

assert args.layers in ['heads', 'all']

DEFAULT_LOGS_DIR = args.logs
COCO_WEIGHTS_PATH = args.coco

print("[INFO] Downloading COCO weights...")
if not os.path.exists(COCO_WEIGHTS_PATH):
    mrcnn.utils.download_trained_weights(COCO_WEIGHTS_PATH)

print("[INFO] Initializing configs...")
config_ = CustomConfig()

K = keras.backend.backend()
if K == 'tensorflow':
    keras.backend.common.image_dim_ordering()
model = modellib.MaskRCNN(mode="training",
                          config=config_,
                          model_dir=DEFAULT_LOGS_DIR)

print("[INFO] Loading COCO weights...")
model.load_weights(COCO_WEIGHTS_PATH,
                   by_name=True,
                   exclude=[
                       "mrcnn_class_logits", "mrcnn_bbox_fc", "mrcnn_bbox",
                       "mrcnn_mask"
                   ])
Beispiel #6
0
def setup_env(project_path):
    """
    Sets up the env settings for the fabric tasks

    Checks your git repo and adds your remotes as
    aliases for those hosts. Letting you do -H web1,web2
    when you have web1 and web2 in your remotes

    Creates roles out of each section in the config file.
    Letting you do -R app-servers and that command will
    be passed to all app servers.

    Provides access to some variables that can be used through
    tasks.

    * **env.deploy_path**: the local location of the deploy folder
    * **env.project_path**: the local location of the root of your project

    * **env.base_remote_path**: the remote path where the code should be deployed
    * **env.configs_path**: the remote path where configs should be deployed

    * **env.config_object**: The servers.ini file loaded by the config parser
    * **env.conf_filename**: The path to the servers.ini file

    * **env.context**: A global context override.
    """

    # Setup fabric env
    env.deploy_path = os.path.join(project_path, 'deploy')
    env.project_path = project_path
    env.project_name = os.path.basename(env.project_path)
    env.build_dir = os.path.join(project_path, '.build')

    BASE = os.path.abspath(os.path.dirname(__file__))
    env.configs_dir = os.path.join(BASE, 'default-configs')
    env.templates_dir = os.path.join(env.configs_dir, 'templates')
    env.context = {}

    env.base_remote_path = '/srv/'
    env.configs_path = '/srv/configs/'
    env.track_static = 'project/source'


    if not env.get('current_platform'):
        env.current_platform = env.platform

    # Read the config and store it in env
    config = CustomConfig()
    env.conf_filename = os.path.abspath(os.path.join(project_path, 'deploy', 'servers.ini'))
    config.read([ env.conf_filename ])
    env.config_object = config

    # Add sections to the roledefs
    for section in config.server_sections():
        if config.has_option(section, CustomConfig.CONNECTIONS):
            env.roledefs[section] = config.get_list(section, CustomConfig.CONNECTIONS)

    env.host_roles = {}
    # Store the configs for each role
    for k,v in env.roledefs.items():
        for host in v:
            env.host_roles[host] = k
Beispiel #7
0
def setup_env(project_path):
    """
    Sets up the env settings for the fabric tasks

    Checks your git repo and adds your remotes as
    aliases for those hosts. Letting you do -H web1,web2
    when you have web1 and web2 in your remotes

    Creates roles out of each section in the config file.
    Letting you do -R app-servers and that command will
    be passed to all app servers.

    Provides access to some variables that can be used through
    tasks.

    * **env.deploy_path**: the local location of the deploy folder
    * **env.project_path**: the local location of the root of your project
    * **env.git_repo_name**: the remote name of the git repo.
    * **env.git_working_dir**: the remote path where the code should be deployed

    * **env.config_object**: The servers.ini file loaded by the config parser
    * **env.conf_filename**: The path to the servers.ini file

    * **env.git_remotes**: A mapping of git remote names to hosts
    * **env.git_reverse**: The reverse of above
    """

    # Setup fabric env
    env.deploy_path = os.path.join(project_path, 'deploy')
    env.project_path = project_path
    env.project_name = os.path.basename(env.project_path)
    env.git_repo_name = GIT_REPO_NAME
    env.git_working_dir = GIT_WORKING_DIR

    BASE = os.path.abspath(os.path.dirname(__file__))
    env.configs_dir = os.path.join(BASE, 'default-configs')

    # Read the config and store it in env
    config = CustomConfig()
    env.conf_filename = os.path.abspath(
        os.path.join(project_path, 'deploy', 'servers.ini'))
    config.read([env.conf_filename])
    env.config_object = config

    # Add sections to the roledefs
    for section in config.server_sections():
        if config.has_option(section, CustomConfig.CONNECTIONS):
            env.roledefs[section] = config.get_list(section,
                                                    CustomConfig.CONNECTIONS)

    env.git_remotes = gather_remotes()
    env.git_reverse = dict([(v, k) for (k, v) in env.git_remotes.iteritems()])

    # Translate any known git names to hosts
    hosts = []
    for host in env.hosts:
        if host in env.git_remotes:
            host = env.git_remotes[host]
        hosts.append(host)
    env.hosts = hosts

    env.project_env_var = None
    try:
        from project.settings import ENV_VAR
        env.project_env_var = ENV_VAR
    except ImportError:
        pass
Beispiel #8
0
def setup_env(project_path):
    """
    Sets up the env settings for the fabric tasks

    Checks your git repo and adds your remotes as
    aliases for those hosts. Letting you do -H web1,web2
    when you have web1 and web2 in your remotes

    Creates roles out of each section in the config file.
    Letting you do -R app-servers and that command will
    be passed to all app servers.

    Provides access to some variables that can be used through
    tasks.

    * **env.deploy_path**: the local location of the deploy folder
    * **env.project_path**: the local location of the root of your project

    * **env.base_remote_path**: the remote path where the code should be deployed
    * **env.configs_path**: the remote path where configs should be deployed

    * **env.config_object**: The servers.ini file loaded by the config parser
    * **env.conf_filename**: The path to the servers.ini file

    * **env.context**: A global context override.
    """

    # Setup fabric env
    env.deploy_path = os.path.join(project_path, 'deploy')
    env.project_path = project_path
    env.project_name = os.path.basename(env.project_path)
    env.build_dir = os.path.join(project_path, '.build')

    BASE = os.path.abspath(os.path.dirname(__file__))
    env.configs_dir = os.path.join(BASE, 'default-configs')
    env.templates_dir = os.path.join(env.configs_dir, 'templates')
    env.context = {}

    env.base_remote_path = '/srv/'
    env.configs_path = '/srv/configs/'
    env.track_static = 'project/source'

    if not env.get('current_platform'):
        env.current_platform = env.platform

    # Read the config and store it in env
    config = CustomConfig()
    env.conf_filename = os.path.abspath(
        os.path.join(project_path, 'deploy', 'servers.ini'))
    config.read([env.conf_filename])
    env.config_object = config

    # Add sections to the roledefs
    for section in config.server_sections():
        if config.has_option(section, CustomConfig.CONNECTIONS):
            env.roledefs[section] = config.get_list(section,
                                                    CustomConfig.CONNECTIONS)

    env.host_roles = {}
    # Store the configs for each role
    for k, v in env.roledefs.items():
        for host in v:
            env.host_roles[host] = k
Beispiel #9
0
#                         "region": "us-east-1"
#                     }
#         },
#         {
#             "name": "Elasticsearch (http anonymous)",
#             "hosts": ["192.168.0.1", "192.168.0.2", "192.168.0.3"],
#             "ssl": false,
#             "port": 9200,
#             "auth": {
#                         "type": "http",
#                         "user": "",
#                         "secret": ""
#                     }
#         }
#         ],
#
#     "KONG_HEALTH_APIKEY" : "API key",
#
#     "kubeconfig" : "<base64 .kube/config content>"
# }
#

secret = CustomConfig.load_json("secret.json")
config = CustomConfig(secret)

# Write the kube config to the default location Config.kubeconfig_path
config.writekubeconfig()

# Start Monitoring
Server(config).startMonitoring()