mirror of
https://github.com/prise6/smart-iss-posts
synced 2024-05-05 23:23:11 +02:00
evaluation des env dans le yaml
This commit is contained in:
parent
f6d8b0c33c
commit
98e01b6a3d
|
@ -8,17 +8,17 @@ import re
|
|||
|
||||
class CollectionManagerFromDirectory:
|
||||
|
||||
def __init__(self, dir, config):
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.dir = self.config.get('directory')['collections']
|
||||
|
||||
jpg_regex = re.compile(".*jpg$")
|
||||
self.pictures_id = [pict for pict in os.listdir(dir) if jpg_regex.match(pict)]
|
||||
self.pictures_id = [pict for pict in os.listdir(self.dir) if jpg_regex.match(pict)]
|
||||
|
||||
self.dir = os.path.join(self.config.project_dir, dir)
|
||||
self.dir_base = os.path.join(self.config.project_dir, self.config.get('directory')['autoencoder']['base'])
|
||||
self.dir_train = os.path.join(self.config.project_dir, self.config.get('directory')['autoencoder']['train'])
|
||||
self.dir_test = os.path.join(self.config.project_dir, self.config.get('directory')['autoencoder']['test'])
|
||||
self.dir_valid = os.path.join(self.config.project_dir, self.config.get('directory')['autoencoder']['valid'])
|
||||
self.dir_base = self.config.get('directory')['autoencoder']['base']
|
||||
self.dir_train = self.config.get('directory')['autoencoder']['train']
|
||||
self.dir_test = self.config.get('directory')['autoencoder']['test']
|
||||
self.dir_valid = self.config.get('directory')['autoencoder']['valid']
|
||||
|
||||
self.seed = self.config.get('training')['seed']
|
||||
self.proportions = self.config.get('training')['proportions']
|
||||
|
|
|
@ -4,19 +4,34 @@ import os
|
|||
import sys
|
||||
import yaml
|
||||
from dotenv import find_dotenv, load_dotenv
|
||||
import re
|
||||
|
||||
load_dotenv(find_dotenv())
|
||||
|
||||
|
||||
class Config:
|
||||
|
||||
def __init__(self, project_dir = os.getenv("PROJECT_DIR"), mode = os.getenv("MODE")):
|
||||
def __init__(self, project_dir = os.getenv("PROJECT_DIR"), mode = os.getenv("MODE")):
|
||||
|
||||
self.project_dir = project_dir
|
||||
self.mode = mode
|
||||
self.project_dir = project_dir
|
||||
self.mode = mode
|
||||
self.path_matcher = re.compile(r'\$\{([^}^{]+)\}')
|
||||
|
||||
with open(os.path.join(self.project_dir, 'config', 'config_%s.yaml' % (self.mode)), 'r') as ymlfile:
|
||||
self.config = yaml.load(ymlfile)
|
||||
yaml.add_implicit_resolver('!path', self.path_matcher, None, yaml.SafeLoader)
|
||||
yaml.add_constructor('!path', self.path_constructor, yaml.SafeLoader)
|
||||
print("ok")
|
||||
|
||||
def get(self, key):
|
||||
return self.config[key]
|
||||
with open(os.path.join(self.project_dir, 'config', 'config_%s.yaml' % (self.mode)), 'r') as ymlfile:
|
||||
self.config = yaml.safe_load(ymlfile)
|
||||
|
||||
def get(self, key):
|
||||
return self.config[key]
|
||||
|
||||
def path_constructor(self, loader, node):
|
||||
''' Extract the matched value, expand env variable, and replace the match '''
|
||||
value = node.value
|
||||
match = self.path_matcher.match(value)
|
||||
env_var = match.group()[2:-1]
|
||||
|
||||
return os.environ.get(env_var) + value[match.end():]
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -12,7 +12,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 22,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -31,7 +31,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -48,12 +48,19 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 24,
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ok\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"cfg = Config()\n",
|
||||
"dir = os.path.join(cfg.project_dir, cfg.get('directory')['collections'])"
|
||||
"cfg = Config()"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -65,16 +72,16 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 25,
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"collection = CollectionManagerFromDirectory(dir = dir, config = cfg)"
|
||||
"collection = CollectionManagerFromDirectory(config = cfg)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 26,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
@ -83,7 +90,7 @@
|
|||
"{'total': 13625}"
|
||||
]
|
||||
},
|
||||
"execution_count": 26,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
|
@ -94,7 +101,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 27,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
@ -492,6 +499,13 @@
|
|||
"source": [
|
||||
"autoencoder.fit_generator(train_generator, steps_per_epoch=1000, epochs = 2)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
|
Loading…
Reference in a new issue