cytometer/models.py
def load_model_with_retries(model, number_of_attempts=1, time_between_attempts=5):
    """
    Wrap keras.models.load_model in a loop so that if the loading fails due to some network filesystem errors, we wait a
    few seconds and then retry to load the model.
    :param model: string with filename containing a keras model.
    :param number_of_attempts: (def 1) Number of times we try to load the model before giving up.
    :param time_between_attempts: (def 5) Seconds between loading attempts.
    :return: keras model.
    """

    # if we are trying to load from a network filesystem, the server hosting the filesystem may return some network
    # error. Because we don't want the computation dying just because of that, we let the user try a couple of times,
    # with a little wait between tries
    for attempt in range(number_of_attempts):
        try:
            model = keras.models.load_model(model)
            break
        except ConnectionResetError:
            print(
                '# ======> ConnectionResetError. Attempt ' + str(attempt) + '/' + str(number_of_attempts) + ' ...')
            time.sleep(time_between_attempts)  # secs
        except RuntimeError as e:
            errno, strerror = e.args
            if strerror == 'Bad file descriptor':
                print(
                    '# ======> RuntimeError (' + strerror + '). Attempt ' + str(attempt) + '/' + str(number_of_attempts) + ' ...')
                time.sleep(time_between_attempts)  # secs
            else:
                # this may be a legitimate RuntimeError that has nothing to do with the network filesystem, so we
                # re-throw the exception
                raise
        except:
            raise

    return model

    Wrap keras.models.load_model in a loop so that if the loading fails due to some network filesystem errors, we wait a
    few seconds and then retry to load the model.
    :param model: string with filename containing a keras model.
    :param number_of_attempts: (def 1) Number of times we try to load the model before giving up.
    :param time_between_attempts: (def 5) Seconds between loading attempts.
    :return: keras model.
    
Wrap keras.models.load_model in a loop so that if the loading fails due to some network filesystem errors, we wait a
few seconds and then retry to load the model.
Wrap keras . models . load_model in a loop so that if the loading fails due to some network filesystem errors we wait a few seconds and then retry to load the model .
def load_model_with_retries(model, number_of_attempts=1, time_between_attempts=5):
    for attempt in range(number_of_attempts):
        try:
            model = keras.models.load_model(model)
            break
        except ConnectionResetError:
            print(
                '# ======> ConnectionResetError. Attempt ' + str(attempt) + '/' + str(number_of_attempts) + ' ...')
            time.sleep(time_between_attempts)  
        except RuntimeError as e:
            errno, strerror = e.args
            if strerror == 'Bad file descriptor':
                print(
                    '# ======> RuntimeError (' + strerror + '). Attempt ' + str(attempt) + '/' + str(number_of_attempts) + ' ...')
                time.sleep(time_between_attempts)  
            else:
                raise
        except:
            raise
    return model
def load_model_with_retries ( model , number_of_attempts = 1 , time_between_attempts = 5 ) : for attempt in range ( number_of_attempts ) : try : model = keras . models . load_model ( model ) break except ConnectionResetError : print ( '# ======> ConnectionResetError. Attempt ' + str ( attempt ) + '/' + str ( number_of_attempts ) + ' ...' ) time . sleep ( time_between_attempts ) except RuntimeError as e : errno , strerror = e . args if strerror == 'Bad file descriptor' : print ( '# ======> RuntimeError (' + strerror + '). Attempt ' + str ( attempt ) + '/' + str ( number_of_attempts ) + ' ...' ) time . sleep ( time_between_attempts ) else : raise except : raise return model
Wrap keras.models.load_model in a loop so that if the loading fails due to some network filesystem errors, we wait a
few seconds and then retry to load the model.
Wrap keras . models . load_model in a loop so that if the loading fails due to some network filesystem errors we wait a few seconds and then retry to load the model .
"""
    Wrap keras.models.load_model in a loop so that if the loading fails due to some network filesystem errors, we wait a
    few seconds and then retry to load the model.
    :param model: string with filename containing a keras model.
    :param number_of_attempts: (def 1) Number of times we try to load the model before giving up.
    :param time_between_attempts: (def 5) Seconds between loading attempts.
    :return: keras model.
    """ # if we are trying to load from a network filesystem, the server hosting the filesystem may return some network # error. Because we don't want the computation dying just because of that, we let the user try a couple of times, # with a little wait between tries # secs # secs # this may be a legitimate RuntimeError that has nothing to do with the network filesystem, so we # re-throw the exception
None
model
string with filename containing a keras model.
string with filename containing a keras model .
number_of_attempts
(def 1) Number of times we try to load the model before giving up.
( def 1 ) Number of times we try to load the model before giving up .
time_between_attempts
(def 5) Seconds between loading attempts.
( def 5 ) Seconds between loading attempts .