Firstly, I want to thank for Alex Donchuk‘s advice in discussion of competition ‘Histopathologic Cancer Detection‘. His advice really helped me a lot. 1. Alex used the ‘SEE-ResNeXt50’. Instead, I used the standard ‘ResNeXt50’. Maybe this is the reason why my score ‘0.9716’ in public leaderboard is not as good… Read more »
To use ResNeXt50, I wrote my code as the API documentation for Keras:
|
keras.applications.resnext.ResNeXt50(...) |
But it reported errors:
|
AttributeError: module 'keras.applications' has no attribute 'resnext' |
That’s weird. The code doesn’t work as documentation said. So I checked the code of Keras-2.2.4 (the version in my computer), and noticed that this version of code use ‘keras_applications’ instead… Read more »
1. How to use part of a model
|
model = load_model(sys.argv[1], custom_objects = {'fmeasure': fmeasure}) branch_model = model.get_layer(name = 'model_1') img_embed = Model(inputs = [branch_model.get_input_at(0)], outputs = [branch_model.get_output_at(0)]) |
The ‘img_embed’ model is part of ‘branch_model’. We should realise that ‘Model()’ is a heavy cpu-cost function so it need to be create only once and then could be used many times. 2. How to save a model when using ‘multi_gpu_model’… Read more »
Firstly, I use a function to transform words into word-embedding:
|
def text_to_array(text, embeddings_index): empty_embed = np.zeros(EMBEDDING_LENGTH, dtype = np.float32) text = text[:-1].split()[:MAX_TEXT_LENGTH] embeds = [] for x in text: em = embeddings_index.get(x) if em is not None: embeds.append(em) embeds += [empty_embed] * (MAX_TEXT_LENGTH - len(embeds)) return np.array(embeds, dtype = np.float32) |
But I noticed that it costs quite a few CPU resource while GPU usage is still low. The reason is simple: using single thread python to do search in dictionary is uneffective. We should use Embedding layer in Keras… Read more »