label-studio-ml-backend
label-studio-ml-backend copied to clipboard
Connection Error docker-compose up ML backend with localhost
I launch label studio server with label-studio start.
Then I lauch my ML backend server with docker-compose up.
I get this error from ner.py (configuration for training the model) :
requests.exceptions.ConnectionError: HTTPConnectionPool(host='78.196.104.25', port=8080): Max retries exceeded with url: /api/projects/3/export?exportType=JSON (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fb95a9f1050>: Failed to establish a new connection: [Errno 111] Connection refused'))
I changed ner.py like this :
ner.py, l. 478 and following :
def fit(
self, event, data, model_type='bert', pretrained_model='bert-base-uncased',
batch_size=32, learning_rate=5e-5, adam_epsilon=1e-8, num_train_epochs=100, weight_decay=0.0, logging_steps=1,
warmup_steps=0, save_steps=50, dump_dataset=True, cache_dir='~/.heartex/cache', train_logs=None,
**kwargs
):
workdir = os.environ['WORK_DIR'] = '<my-work-dir>'
# URL en dur
download_url = "http://localhost:8080/api/projects/3/export?exportType=JSON"
token = "<my_token>"
# Requête API
response = requests.get(download_url, headers={'Authorization': f'Token {token}'})
if response.status_code != 200:
raise Exception(f"Can't load task data using {download_url}, "
f"response status_code = {response.status_code}")
if workdir is None:
raise ValueError('Specify "WORK_DIR" environmental variable to store model checkpoints.')
train_logs = train_logs or os.path.join(workdir, 'train_logs')
os.makedirs(train_logs, exist_ok=True)
logger.debug('Prepare models')
cache_dir = os.path.expanduser(cache_dir)
os.makedirs(cache_dir, exist_ok=True)
model_type = model_type.lower()
# assert model_type in MODEL_CLASSES.keys(), f'Input model type {model_type} not in {MODEL_CLASSES.keys()}'
# assert pretrained_model in ALL_MODELS, f'Pretrained model {pretrained_model} not in {ALL_MODELS}'
tokenizer = AutoTokenizer.from_pretrained(pretrained_model, cache_dir=cache_dir)
logger.debug('Read data')
# read input data stream
completions = response.json()
texts, list_of_spans = [], []
It has previously worked with label-studio start ner_adapted --init --ml-backend http://localhost:9090.
Solved it byr replacing localhost by host.docker.internal :
download_url = "http://host.docker.internal:8080/api/projects/3/export?exportType=JSON"