def get_layer_outputs(layer_name, input_path): is_grayscale = (input_channels == 1) input_img = load_img(join(abspath(input_folder), input_path), single_input_shape, grayscale=is_grayscale) output_generator = get_outputs_generator(model, layer_name) with get_evaluation_context(): layer_outputs = output_generator(input_img)[0] output_files = [] if keras.backend.backend() == 'theano': #correct for channel location difference betwen TF and Theano layer_outputs = np.rollaxis(layer_outputs, 0, 3) for z in range(0, layer_outputs.shape[2]): img = layer_outputs[:, :, z] deprocessed = deprocess_image(img) filename = get_output_name(temp_folder, layer_name, input_path, z) output_files.append(relpath(filename, abspath(temp_folder))) imsave(filename, deprocessed) return jsonify(output_files)
def save_layer_img(layer_outputs, layer_name, idx, temp_folder, input_path): filename = get_output_filename(layer_name, idx, temp_folder, input_path) imsave(filename, deprocess_image(layer_outputs)) return relpath(filename, abspath(temp_folder))
def save_layer_img(layer_outputs, layer_name, idx, temp_folder, input_path): filename = get_output_filename(layer_name, idx, temp_folder, input_path) imageio.imwrite(filename, (deprocess_image(layer_outputs)*255).astype(np.uint8)) return relpath(filename, abspath(temp_folder))