<jupyter_start><jupyter_text>Low&Mid level feature map<jupyter_code>model_h.summary()
def extract_features_hiar_models(model, x, layer_id, filters, layer_num_list):
    '''
    提取指定模型指定层指定数目的feature map并输出到一幅图上.
    :param ins: 模型实例
    if len(ins) != 2:
        print('parameter error:(model, instance)')
        return None
    :param layer_id: 提取指定层特征
    :param filters: 每层提取的feature map数
    :param layer_num_list: 一共提取多少层feature map
    :return: None
    '''
    if type(layer_id) == type(1):
        model_extractfeatures = Model(inputs=model[i].input, outputs=model[i].get_layer(index=layer_id).output)
    else:
        model_extractfeatures = Model(inputs=model[i].input, outputs=model[i].get_layer(name=layer_id).output)
    #model_extractfeatures.summary()
    fc2_features = model_extractfeatures.predict(x)
    if filters > len(fc2_features[0][0][0]):
        print('layer number error.', len(fc2_features[0][0][0]),',',filters)
        return None
    for i in range(filters):
        #plt.subplots_adjust(left=0, right=1, bottom=0, top=1)
        plt.subplot(filters, len(layer_num_list), layer_num_list.index(layer_id) + 1 + i * len(layer_num_list) )
        plt.axis("off")
        if i < len(fc2_features[0][0][0]):
            plt.imshow(fc2_features[0, :, :, i])

# 层数、模型、卷积核数
def extract_features_batch_hiar_models(model, x, filters, layer_num_list, path):
    '''
    批量提取特征
    :param layer_num: 层数
    :param model: 模型
    :param filters: feature map数
    :return: None
    '''
    #plt.figure(figsize=(filters, layer_num))
    plt.subplot(filters, len(layer_num_list), 1)
    for i in layer_num_list:
        extract_features_hiar_models(model, x, i, filters, layer_num_list)
    plt.savefig(path, dpi=250, quality=95)
    plt.show()
    

for i in range(20):
    print("filter_", str(i))
    extract_features_batch_hiar_models(model_h, img_arr, i, [1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 40, 50, 70, 90, 110, 130], '../results/samples/sample_all_model_filter'+str(i)+'.jpg')<jupyter_output><empty_output><jupyter_text>base feature map<jupyter_code>def extract_features_allmodels(model, x, layer_id, filter_id, layer_num_list):
    '''
    提取指定模型指定层指定数目的feature map并输出到一幅图上.
    :param ins: 模型实例
    if len(ins) != 2:
        print('parameter error:(model, instance)')
        return None
    :param layer_id: 提取指定层特征
    :param filters: 每层提取的feature map数
    :param layer_num_list: 一共提取多少层feature map
    :return: None
    '''
    for i in range(len(model)):
        if type(layer_id) == type(1):
            model_extractfeatures = Model(inputs=model[i].input, outputs=model[i].get_layer(index=layer_id).output)
        else:
            model_extractfeatures = Model(inputs=model[i].input, outputs=model[i].get_layer(name=layer_id).output)
        #model_extractfeatures.summary()
        fc2_features = model_extractfeatures.predict(x)
        if filter_id > len(fc2_features[0][0][0]):
            print('layer number error.', len(fc2_features[0][0][0]),',',filter_id)
            return None
        #plt.subplots_adjust(left=0, right=1, bottom=0, top=1)
        plt.subplot(len(model), len(layer_num_list), layer_num_list.index(layer_id) + 1 + i * len(layer_num_list) )
        plt.axis("off")
        if filter_id < len(fc2_features[0][0][0]):
            plt.imshow(fc2_features[0, :, :, filter_id])
            plt.savefig("../results/1.jpg", dpi=250, quality=95)

# 层数、模型、卷积核数
def extract_features_batch_allmodels(model, x, filter_id, layer_num_list, path):
    '''
    批量提取特征
    :param layer_num: 层数
    :param model: 模型
    :param filters: feature map数
    :return: None
    '''
    #plt.figure(figsize=(filters, layer_num))
    plt.subplot(len(model), len(layer_num_list), 1)
    for i in layer_num_list:
        extract_features_allmodels(model, x, i, filter_id, layer_num_list)
    plt.savefig(path, dpi=250, quality=95)
    plt.show()
    

#for i in range(20):
#    print("filter_", str(i))
extract_features_batch_allmodels([model_h, model_g], img_arr, 0, [1, 2, 3, 4, 5, 10, 15, 20, 25, 30, 40, 50, 70, 90, 110, 130], '../results/samples/sample_all_model_filter'+str(i)+'.jpg')
Model(inputs=model.input, outputs=model.get_layer(index=layer_id).output)<jupyter_output><empty_output><jupyter_text>Weights<jupyter_code>from src.network.hiarBayesGoogLenet import hiarBayesGoogLeNet
model_hr = hiarBayesGoogLeNet.build(image_height, image_width, 3, [len(low_level), len(mid_level), len(high_level)])
model_hr.load_weights("/home/anhaoran/codes/pedestrian_attibutes_wpal/models/imagenet_models/hiarBayesGoogLeNet_PETA/binary61_multi_final_model.h5")
model_hr.summary()
weights = model_hr.get_layer('high_cond').get_weights()
print(weights)
print(weights[0].shape)
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

plt.subplots(figsize=(9, 9))
sns.heatmap(weights[0], cmap="Blues", square=True, xticklabels = ['personalLess15', 'personalLess30', 'personalLess45', 'personalLess60', 'personalLarger60', 'lowerBodyCapri', 'lowerBodyCasual', 'upperBodyCasual', 'personalFemale', 'lowerBodyFormal', 'upperBodyFormal', 'lowerBodyPlaid', 'personalMale', 'upperBodyPlaid'], yticklabels = ['upperBodyLogo', 'lowerBodyThinStripes', 'upperBodyThinStripes', 'upperBodyThickStripes', 'accessoryHeadphone', 'carryingBabyBuggy', 'carryingBackpack', 'hairBald', 'footwearBoots', 'carryingOther', 'carryingShoppingTro', 'carryingUmbrella', 'carryingFolder', 'accessoryHairBand', 'accessoryHat', 'lowerBodyHotPants', 'upperBodyJacket', 'lowerBodyJeans', 'accessoryKerchief', 'footwearLeatherShoes', 'hairLong', 'lowerBodyLongSkirt', 'upperBodyLongSleeve', 'carryingLuggageCase', 'carryingMessengerBag', 'accessoryMuffler', 'accessoryNothing', 'carryingNothing', 'upperBodyNoSleeve', 'carryingPlasticBags', 'footwearSandals', 'footwearShoes', 'hairShort', 'lowerBodyShorts', 'upperBodyShortSleeve', 'lowerBodyShortSkirt', 'footwearSneakers', 'footwearStocking', 'upperBodySuit', 'carryingSuitcase', 'lowerBodySuits', 'accessorySunglasses', 'upperBodySweater', 'lowerBodyTrousers', 'upperBodyTshirt', 'upperBodyOther', 'upperBodyVNeck'])
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14253023864007847, 'fraction_numerical': 0.02337365152010461, 'mean_word_length': 5.155935613682092, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '173441', 'license': 'Net-SNMP', 'n_tokens_mistral': 2362, 'n_tokens_neox': 2273, 'n_words': 382, 'path': 'notebook/.ipynb_checkpoints/plot_featuremap&weights-checkpoint.ipynb', 'repo_name': 'waterahr/HR-Net', 'size': '6118'}