Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

路径相关的问题 #1

Open
diehualong opened this issue Sep 4, 2023 · 11 comments
Open

路径相关的问题 #1

diehualong opened this issue Sep 4, 2023 · 11 comments

Comments

@diehualong
Copy link

作者您好。我在阅读代码的过程中,发现处理数据集后保存的文件夹名称是hanchuan_15等。如下图所示。
image
但是,在训练部分代码中,读取数据集的路径中出现了一个whuhi_image_2percent的文件夹,这个文件夹是怎么得到的呢?
image

@DotWang
Copy link
Owner

DotWang commented Sep 6, 2023

@diehualong 上图是在windows电脑上将高光谱变成三波段图像保存到hanchuan_15文件夹,下图是在Linux服务器上读取文件夹中的图片,为了与原有高光谱数据集区分,该hanchuan_15文件夹放在whu_hi新建的whuhi_image_2percent文件夹下

@S-haaaaa
Copy link

作者您好。我在调试训练的时候,出现了whuhi_image_2percent文件夹。文件夹里的图片怎么获取呢?是否可以提供完整的源代码?

@S-haaaaa
Copy link

1
作者你好。这个包的问题应该怎么解决?

@DotWang
Copy link
Owner

DotWang commented Nov 16, 2023

@19979548798 注释掉,DCN-T用不到这俩

@DotWang
Copy link
Owner

DotWang commented Nov 16, 2023

@19979548798 请问这是哪个文件里边的?

@S-haaaaa
Copy link

S-haaaaa commented Nov 17, 2023

@19979548798 请问这是哪个文件里边的?
开源文件里面有好多文件夹都没给出,都不知道这整个项目得文件夹层级结构。

image
WHU-HIi.py文件里面出现的,这个文件夹里面的图片应该怎么获取呢?

image
这个是骨干网络swin里面的,注释了后面有会调用这个会报错
image

@DotWang
Copy link
Owner

DotWang commented Nov 17, 2023

@19979548798 第一张图,你把WHU-Hi数据集下下来看看他的文件夹结构就知道了;

第二、三张图,swin这个模型代码应该是从我们其他用了mmseg, mmcv系列的项目中拿过来的,而我的项目都共用一套环境,所以可能我没发现报错,这个解决方法有两种,第一种是你参考一下我github首页这几个跟遥感大模型相关的仓库,就知道mmcv和mmseg怎么用了,第二种是,load_checkpoint其实和torch.load是一个意思,这部分代码你重构一下

@S-haaaaa
Copy link

@19979548798 第一张图,你把WHU-Hi数据集下下来看看他的文件夹结构就知道了;

第二、三张图,swin这个模型代码应该是从我们其他用了mmseg, mmcv系列的项目中拿过来的,而我的项目都共用一套环境,所以可能我没发现报错,这个解决方法有两种,第一种是你参考一下我github首页这几个跟遥感大模型相关的仓库,就知道mmcv和mmseg怎么用了,第二种是,load_checkpoint其实和torch.load是一个意思,这部分代码你重构一下
whuhi_image_2percent文件夹里面的.png图片没有,WHU-Hi数据集里面只有三个区域d的mat文件

@DotWang
Copy link
Owner

DotWang commented Nov 17, 2023

@19979548798 可以参考一下swin.py

    def init_weights(self, pretrained):

        ckpt = torch.load(pretrained, map_location='cpu')
        
        if 'state_dict' in ckpt:
            _state_dict = ckpt['state_dict']
        elif 'model' in ckpt:
            _state_dict = ckpt['model']
        else:
            _state_dict = ckpt

        state_dict = OrderedDict()
        for k, v in _state_dict.items():
            if k.startswith('backbone.'):
                state_dict[k[9:]] = v
            else:
                state_dict[k] = v

        # strip prefix of state_dict
        if list(state_dict.keys())[0].startswith('module.'):
            state_dict = {k[7:]: v for k, v in state_dict.items()}

        # reshape absolute position embedding
        if state_dict.get('absolute_pos_embed') is not None:
            absolute_pos_embed = state_dict['absolute_pos_embed']
            N1, L, C1 = absolute_pos_embed.size()
            N2, C2, H, W = self.absolute_pos_embed.size()
            if N1 != N2 or C1 != C2 or L != H * W:
                warnings.warn('Error in loading absolute_pos_embed, pass')
            else:
                state_dict['absolute_pos_embed'] = absolute_pos_embed.view(
                    N2, H, W, C2).permute(0, 3, 1, 2).contiguous()

        # interpolate position bias table if needed
        relative_position_bias_table_keys = [
            k for k in state_dict.keys()
            if 'relative_position_bias_table' in k
        ]

        for table_key in relative_position_bias_table_keys:
            table_pretrained = state_dict[table_key]
            table_current = self.state_dict()[table_key]
            L1, nH1 = table_pretrained.size()
            L2, nH2 = table_current.size()
            if nH1 != nH2:
                warnings.warn(f'Error in loading {table_key}, pass')
            elif L1 != L2:
                S1 = int(L1**0.5)
                S2 = int(L2**0.5)
                table_pretrained_resized = F.interpolate(
                    table_pretrained.permute(1, 0).reshape(1, nH1, S1, S1),
                    size=(S2, S2),
                    mode='bicubic')
                state_dict[table_key] = table_pretrained_resized.view(
                    nH2, L2).permute(1, 0).contiguous()

        # print('##############')

        # print(self.state_dict().keys())

        # print('$$$$$$$$$$$$$$')

        # print(state_dict.keys())

        # load state_dict
        msg = self.load_state_dict(state_dict, False)
        print(msg)

@DotWang
Copy link
Owner

DotWang commented Nov 17, 2023

@19979548798 。。你看论文了吗,将高光谱数据集转换成RGB图像是我们的创新点之一,原始WHU-Hi当然没有,这部分代码我放在jupyter notebook里了,你看看readme

@DotWang
Copy link
Owner

DotWang commented Nov 17, 2023

@diehualong 上图是在windows电脑上将高光谱变成三波段图像保存到hanchuan_15文件夹,下图是在Linux服务器上读取文件夹中的图片,为了与原有高光谱数据集区分,该hanchuan_15文件夹放在whu_hi新建的whuhi_image_2percent文件夹下

@19979548798

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants